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 docs state that, "Reversing is often more descriptive than hard-coding the URLs." What does this mean?!

I'm doing some work with Flask and, in the docs, five reasons are given for using url_for. The top one states that, "Reversing is often more descriptive than hard-coding the URLs."

What does this mean? What is meant by 'reversing' in this context?

1 Answer

Jeff Muday
MOD
Jeff Muday
Treehouse Moderator 28,732 Points

url_for(<function_name>, {parameters} ) generates a dynamic URL-- you knew that already.

Static URLs are great for simple applications, and in some ways might be preferred (performance-wise).

The use of url_for() makes the code you write more maintainable as it clearly shows the URL functional-endpoint, and the parameters being sent as being independent entities rather than constructed as an aggregate URL.

Another advantage is the ability to change the top-level static routes and not have to dive into the code and templates to match-up/edit all the instances where the route was statically defined in the code.