ConstantinL ConstantinL - 1 year ago 111
Python Question

Log form data for Flask request

I am learning Flask and have trouble reproducing a tutorial. I am using Flask 0.10.1 on Python 3.5.1.

I have the following app, which has a small form on the 'Add' page. I would like to display in the console everything I submit through the form, but I don't get anything except a simple POST message below.

Any help appreciated. Thank you!

enter image description here

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

app = Flask(__name__)

bookmarks = []

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

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']
app.logger.debug('stored url: ')
return render_template('add.html')

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

if __name__ == '__main__':

Answer Source

The documentation states:

If the application runs in production mode (which it will do on your server) you might not see any log messages.

Do you run your code in production or debug mode?

Make sure it is run in Debug mode by setting the environment variable FLASK_DEBUG to true and try again, it should then appear.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download