mirror of
https://github.com/django/django.git
synced 2025-08-04 10:59:45 +00:00
Fixed #34140 -- Reformatted code blocks in docs with blacken-docs.
This commit is contained in:
parent
6015bab80e
commit
14459f80ee
193 changed files with 5797 additions and 4481 deletions
|
@ -180,9 +180,9 @@ An example might clarify things here:
|
|||
|
||||
>>> from urllib.parse import quote
|
||||
>>> from django.utils.encoding import iri_to_uri
|
||||
>>> quote('Paris & Orléans')
|
||||
>>> quote("Paris & Orléans")
|
||||
'Paris%20%26%20Orl%C3%A9ans'
|
||||
>>> iri_to_uri('/favorites/François/%s' % quote('Paris & Orléans'))
|
||||
>>> iri_to_uri("/favorites/François/%s" % quote("Paris & Orléans"))
|
||||
'/favorites/Fran%C3%A7ois/Paris%20%26%20Orl%C3%A9ans'
|
||||
|
||||
If you look carefully, you can see that the portion that was generated by
|
||||
|
@ -200,9 +200,9 @@ An example to demonstrate:
|
|||
.. code-block:: pycon
|
||||
|
||||
>>> from django.utils.encoding import uri_to_iri
|
||||
>>> uri_to_iri('/%E2%99%A5%E2%99%A5/?utf8=%E2%9C%93')
|
||||
>>> uri_to_iri("/%E2%99%A5%E2%99%A5/?utf8=%E2%9C%93")
|
||||
'/♥♥/?utf8=✓'
|
||||
>>> uri_to_iri('%A9hello%3Fworld')
|
||||
>>> uri_to_iri("%A9hello%3Fworld")
|
||||
'%A9hello%3Fworld'
|
||||
|
||||
In the first example, the UTF-8 characters are unquoted. In the second, the
|
||||
|
@ -245,8 +245,9 @@ above_. For example::
|
|||
from urllib.parse import quote
|
||||
from django.utils.encoding import iri_to_uri
|
||||
|
||||
|
||||
def get_absolute_url(self):
|
||||
url = '/person/%s/?x=0&y=0' % quote(self.location)
|
||||
url = "/person/%s/?x=0&y=0" % quote(self.location)
|
||||
return iri_to_uri(url)
|
||||
|
||||
This function returns a correctly encoded URL even if ``self.location`` is
|
||||
|
@ -262,7 +263,8 @@ Templates
|
|||
Use strings when creating templates manually::
|
||||
|
||||
from django.template import Template
|
||||
t2 = Template('This is a string template.')
|
||||
|
||||
t2 = Template("This is a string template.")
|
||||
|
||||
But the common case is to read templates from the filesystem. If your template
|
||||
files are not stored with a UTF-8 encoding, adjust the :setting:`TEMPLATES`
|
||||
|
@ -303,6 +305,7 @@ environment. Check your current configuration in an interactive Python shell by
|
|||
running::
|
||||
|
||||
import sys
|
||||
|
||||
sys.getfilesystemencoding()
|
||||
|
||||
This should output "UTF-8".
|
||||
|
@ -340,7 +343,7 @@ the ``encoding`` attribute on an ``HttpRequest`` instance. For example::
|
|||
|
||||
def some_view(request):
|
||||
# We know that the data must be encoded as KOI8-R (for some reason).
|
||||
request.encoding = 'koi8-r'
|
||||
request.encoding = "koi8-r"
|
||||
...
|
||||
|
||||
You can even change the encoding after having accessed ``request.GET`` or
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue