2016-09-19 58 views
0

我正在学习烧瓶并且无法复制教程。我在Python 3.5.1上使用Flask 0.10.1。烧瓶请求的日志格式数据

我有以下应用程序,它在'添加'页面上有一个小窗体。我想在控制台中显示我通过表单提交的所有内容,但除了下面的简单POST消息之外,我什么也没有得到。

任何帮助表示赞赏。谢谢!

enter image description here

from flask import Flask, render_template, url_for, request 
from datetime import datetime 
from logging import DEBUG 



app = Flask(__name__) 
app.logger.setLevel(DEBUG) 

bookmarks = [] 

def store_bookmark(url): 
    bookmarks.append(dict (
     url = url, 
     user= 'constantin', 
     date = datetime.utcnow() 
    )) 

@app.route('/') 
@app.route('/index') 
def index(): 
    return render_template('index.html',title='TEST') 


@app.route('/add',methods = ['GET','POST']) 
def add(): 
    if request.method == 'POST': 
     url = request.form['url'] 
     store_bookmark(url) 
     app.logger.debug('stored url: ') 
    return render_template('add.html') 


@app.errorhandler(404) 
def page_not_found(e): 
    return render_template('404.html'),404 


if __name__ == '__main__': 
    app.run() 

回答

1

documentation状态:

如果在生产模式下运行应用程序(它会做你的服务器上),你可能看不到任何日志消息。

您是否在生产或调试模式下运行代码?

通过将环境变量FLASK_DEBUG设置为true并重试,确保它在Debug mode中运行,然后应该显示它。

+0

我在运行服务器之前设置了FLASK_DEBUG = 1 - 作为魅力工作。谢谢! – ConstantinL

+0

是的 - 我无法在表单中记录数据,因为我没有启用调试模式。 – ConstantinL