app.py 文件源码

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

项目:microflack_messages 作者: miguelgrinberg 项目源码 文件源码
def new_message():
    """
    Post a new message.
    This endpoint is requires a valid user token.
    """
    msg = Message(user_id=g.jwt_claims['user_id'])
    msg.from_dict(request.get_json(), partial_update=False)
    msg.html = '...'
    db.session.add(msg)
    db.session.commit()
    r = jsonify(msg.to_dict())
    r.status_code = 201
    r.headers['Location'] = url_for('get_message', id=msg.id)

    # render the markdown and expand the links in a background task
    if app.config['TESTING']:
        # for unit tests, render synchronously
        render_message(msg.id)
    else:
        # asynchronous rendering
        render_thread = threading.Thread(target=render_message,
                                         args=(msg.id,))
        render_thread.start()
    return r
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号