Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python Flask with SQLAlchemy Basics Creating a Basic Website with Flask Set Up a Form

Jorge Grajeda
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Jorge Grajeda
Python Development Techdegree Graduate 8,186 Points

"Make sure to print out request.form inside of the form function before the return".

It is asking that "Make sure to print out request.form inside of the form function before the return". But the request.form is inside of the form function, could somebody help me out with this ?

form.html
{% extends 'layout.html' %}

{% block content %}
    <form action="">
        <input type="text" name="name" id="firstName" placeholder="First Name">
        <label for="firstName">What is your first name?</label>
        <button type="submit">Submit</button>
    </form>
{% endblock %}
app.py
from flask import Flask, url_for, render_template, request

app = Flask(__name__)

@app.route('/form', methods=['GET', 'POST'])
def form():
    if request.form == 'POST':
        print(request.form)
    return render_template('form.html')

if __name__ == '__main__':
    app.run(host='0.0.0.0', port=8000)

1 Answer

Travis Alstrand
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Travis Alstrand
Treehouse Teacher

Hey Jorge Grajeda ! :wave:

This isn't currently working because the Challenge is being specific and picky. It didn't ask for you to create that conditional checking if the request.form exists, so removing that and left-indenting your print() statement solves this issue.

However, I very much like that you added that conditional personally. You have the right mental approach here :thumbsup: this challenge was just being very particular about the results it wanted is all. Nice work!

from flask import Flask, url_for, render_template, request

app = Flask(__name__)

@app.route('/form', methods=['GET', 'POST'])
def form():
    print(request.form)
    return render_template('form.html')

if __name__ == '__main__':
    app.run(host='0.0.0.0', port=8000)