app.py 文件源码

python
阅读 61 收藏 0 点赞 0 评论 0

项目:commento 作者: rahulrrixe 项目源码 文件源码
def new():

    if request.method == 'POST':
        # The request is POST with some data, get POST data and validate it.
        # The form data is available in request.form dictionary.
        # Check if all the fields are entered. If not, raise an error
        if not request.form['name'] or not request.form['email'] or not request.form['comment']:
            flash('Please enter all the fields', 'error')
        else:
            # The data is valid. So create a new 'Comments' object
            # to save to the database
            comment = Comments(request.form['name'],
                               request.form['email'],
                               request.form['comment'])

            # Add it to the SQLAlchemy session and commit it to
            # save it to the database
            db.session.add(comment)
            db.session.commit()

            # Flash a success message
            flash('Comment was successfully submitted')

            # Redirect to the view showing all the comments
            return redirect(url_for('show_all'))

    # Render the form template if the request is a GET request or
    # the form validation failed
    return render_template('new.html')


# This is the code that gets executed when the current python file is
# executed.
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号