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

Inside of the form.html file, you will connect the form to your route. In the <form> tag, set the action attribute with

Please help, why my code is incorrect?

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

{% block content %}
    <form action="{{ url_for('form') }}" method = "POST">
        <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():
    print(request.form)
    return render_template('form.html')


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

1 Answer

Megan Amendola
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree seal-36
Megan Amendola
Treehouse Teacher

Hi! You don't want any spaces here <form action="{{ url_for('form') }}" method = "POST"> instead it should be <form action="{{ url_for('form') }}" method="POST">

Works now, thank you. Does it mean "method = "POST" has to be no space or just the design or this question? Thank you