summaryrefslogtreecommitdiff
path: root/docs/ref/unicode.txt
diff options
context:
space:
mode:
authordjango-bot <ops@djangoproject.com>2023-02-28 20:53:28 +0100
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2023-03-01 13:03:56 +0100
commit14459f80ee3a9e005989db37c26fd13bb6d2fab2 (patch)
treeeb62429ed696ed3a5389f3a676aecfc6d15a99cc /docs/ref/unicode.txt
parent6015bab80e28aef2669f6fac53423aa65f70cb08 (diff)
Fixed #34140 -- Reformatted code blocks in docs with blacken-docs.
Diffstat (limited to 'docs/ref/unicode.txt')
-rw-r--r--docs/ref/unicode.txt17
1 files changed, 10 insertions, 7 deletions
diff --git a/docs/ref/unicode.txt b/docs/ref/unicode.txt
index b73814c861..81a0b08aad 100644
--- a/docs/ref/unicode.txt
+++ b/docs/ref/unicode.txt
@@ -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