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 trialHanwen Zhang
20,084 PointsInside 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?
{% 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 %}
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
Treehouse TeacherHi! 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">
Hanwen Zhang
20,084 PointsHanwen Zhang
20,084 PointsWorks now, thank you. Does it mean "method = "POST" has to be no space or just the design or this question? Thank you
Megan Amendola
Treehouse TeacherMegan Amendola
Treehouse TeacherFor HTML attributes, you write them without the spaces. For example: https://www.w3schools.com/tags/att_form_method.asp