Skip to content
Myr

rewrite quickstart Unique URLs section

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by David Lord · committed by David Lord · parent b16592a · Browse files · 1 file+13 added−14 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+13 added−14 removed

  • other:+13 added−14 removed

1 file+13 added−14 removed

modified:docs/quickstart.rst+13 added-14 removed
226 unmodified lines
227228Unique URLs / Redirection Behavior229``````````````````````````````````230231Take these two rules::231The following two rules differ in their use of a trailing slash. ::232233 @app.route('/projects/')234 def projects():235 return 'The project page'
1 unmodified line
237 @app.route('/about')238 def about():239 return 'The about page'240241Though they look similar, they differ in their use of the trailing slash in242the URL. In the first case, the canonical URL for the ``projects`` endpoint243uses a trailing slash. It's similar to a folder in a file system; if you244access the URL without a trailing slash, Flask redirects you to the245canonical URL with the trailing slash.241The canonical URL for the ``projects`` endpoint has a trailing slash.242It's similar to a folder in a file system. If you access the URL without243a trailing slash, Flask redirects you to the canonical URL with the244trailing slash.245247In the second case, however, the URL definition lacks a trailing slash,248like the pathname of a file on UNIX-like systems. Accessing the URL with a249trailing slash produces a 404 “Not Found” error.246The canonical URL for the ``about`` endpoint does not have a trailing247slash. It's similar to the pathname of a file. Accessing the URL with a248trailing slash produces a 404 "Not Found" error. This helps keep URLs249unique for these resources, which helps search engines avoid indexing250the same page twice.251251This behavior allows relative URLs to continue working even if the trailing252slash is omitted, consistent with how Apache and other servers work. Also,253the URLs will stay unique, which helps search engines avoid indexing the254same page twice.252253.. _url-building:254255URL Building
11 unmodified lines
2672. You can change your URLs in one go instead of needing to remember to268 manually change hard-coded URLs.2693. URL building handles escaping of special characters and Unicode data270 transparently.2714. The generated paths are always absolute, avoiding unexpected behavior272 of relative paths in browsers.2744. If your application is placed outside the URL root, for example, in2735. If your application is placed outside the URL root, for example, in274 ``/myapplication`` instead of ``/``, :func:`~flask.url_for` properly275 handles that for you.276277For example, here we use the :meth:`~flask.Flask.test_request_context` method
572 unmodified lines