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!

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 Basics Character Builder Forms

Joseph Michelini
.a{fill-rule:evenodd;}techdegree seal-36
Joseph Michelini
Python Development Techdegree Graduate 18,692 Points

How were we able to use url_for in index.html before we imported it?

Right before we import redirect and url_for, we use url_for in index.html, test the code and it successfully finds the /save route.

<form action="{{ url_for('save') }}" method="POST">

I was just curious why this works before we import url_for.


1 Answer

Jennifer Nordell
Jennifer Nordell
Treehouse Teacher

Hi there, Joseph Michelini ! The short answer is: we don't need to import anything into a template for it to work. I know it looks that way, but a Flask template has access to a few variables just out of the box. Because index.html is a Flask template, it has access to url_for just naturally. The same is not true for app.py. I recommend taking a look at the Flask template documentation for information on what variables/methods are available to template a just "out of the box".

Hope this helps! :sparkles: