Merge pull request #2637 from pallets/quickstart-unique-urls
rewrite quickstart Unique URLs section
This commit is contained in:
commit
b0c1da1e7e
1 changed files with 13 additions and 14 deletions
|
|
@ -228,7 +228,7 @@ Converter types:
|
||||||
Unique URLs / Redirection Behavior
|
Unique URLs / Redirection Behavior
|
||||||
``````````````````````````````````
|
``````````````````````````````````
|
||||||
|
|
||||||
Take these two rules::
|
The following two rules differ in their use of a trailing slash. ::
|
||||||
|
|
||||||
@app.route('/projects/')
|
@app.route('/projects/')
|
||||||
def projects():
|
def projects():
|
||||||
|
|
@ -238,20 +238,17 @@ Take these two rules::
|
||||||
def about():
|
def about():
|
||||||
return 'The about page'
|
return 'The about page'
|
||||||
|
|
||||||
Though they look similar, they differ in their use of the trailing slash in
|
The canonical URL for the ``projects`` endpoint has a trailing slash.
|
||||||
the URL. In the first case, the canonical URL for the ``projects`` endpoint
|
It's similar to a folder in a file system. If you access the URL without
|
||||||
uses a trailing slash. It's similar to a folder in a file system; if you
|
a trailing slash, Flask redirects you to the canonical URL with the
|
||||||
access the URL without a trailing slash, Flask redirects you to the
|
trailing slash.
|
||||||
canonical URL with the trailing slash.
|
|
||||||
|
|
||||||
In the second case, however, the URL definition lacks a trailing slash,
|
The canonical URL for the ``about`` endpoint does not have a trailing
|
||||||
like the pathname of a file on UNIX-like systems. Accessing the URL with a
|
slash. It's similar to the pathname of a file. Accessing the URL with a
|
||||||
trailing slash produces a 404 “Not Found” error.
|
trailing slash produces a 404 "Not Found" error. This helps keep URLs
|
||||||
|
unique for these resources, which helps search engines avoid indexing
|
||||||
|
the same page twice.
|
||||||
|
|
||||||
This behavior allows relative URLs to continue working even if the trailing
|
|
||||||
slash is omitted, consistent with how Apache and other servers work. Also,
|
|
||||||
the URLs will stay unique, which helps search engines avoid indexing the
|
|
||||||
same page twice.
|
|
||||||
|
|
||||||
.. _url-building:
|
.. _url-building:
|
||||||
|
|
||||||
|
|
@ -271,7 +268,9 @@ Why would you want to build URLs using the URL reversing function
|
||||||
manually change hard-coded URLs.
|
manually change hard-coded URLs.
|
||||||
3. URL building handles escaping of special characters and Unicode data
|
3. URL building handles escaping of special characters and Unicode data
|
||||||
transparently.
|
transparently.
|
||||||
4. If your application is placed outside the URL root, for example, in
|
4. The generated paths are always absolute, avoiding unexpected behavior
|
||||||
|
of relative paths in browsers.
|
||||||
|
5. If your application is placed outside the URL root, for example, in
|
||||||
``/myapplication`` instead of ``/``, :func:`~flask.url_for` properly
|
``/myapplication`` instead of ``/``, :func:`~flask.url_for` properly
|
||||||
handles that for you.
|
handles that for you.
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue