Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

view.py优化 #4

Closed
colinz2 opened this issue Nov 5, 2018 · 2 comments
Closed

view.py优化 #4

colinz2 opened this issue Nov 5, 2018 · 2 comments

Comments

@colinz2
Copy link

colinz2 commented Nov 5, 2018

messages = Message.query.order_by(Message.timestamp.desc()).all() 移动到最后的return之前。

@app.route('/', methods=['GET', 'POST'])
def index():
    form = HelloForm()
    if form.validate_on_submit():
        name = form.name.data
        body = form.body.data
        message = Message(body=body, name=name)
        db.session.add(message)
        db.session.commit()
        flash('Your message have been sent to the world!')
        return redirect(url_for('index'))
    messages = Message.query.order_by(Message.timestamp.desc()).all()
    return render_template('index.html', form=form, messages=messages)
@greyli
Copy link
Owner

greyli commented Nov 6, 2018

谢谢,这里考虑的不够周全,周末会添加到「可改进实现」里。

@greyli
Copy link
Owner

greyli commented Dec 7, 2018

已更新(Link)。

@greyli greyli closed this as completed Dec 7, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants