summaryrefslogtreecommitdiff
path: root/docs/topics
diff options
context:
space:
mode:
authorCurtis Maloney <curtis@tinbrain.net>2018-09-11 03:00:34 +1000
committerTim Graham <timograham@gmail.com>2018-09-10 14:38:08 -0400
commit1853e2dbf2e290ec04e3389d523bbe4bad94a42e (patch)
treec63e2721c7e691ae88a4ad9e5135b1f042bab857 /docs/topics
parent2b2474b75d63fcded37b872fcd2bb543d7502a8a (diff)
[2.1.x] Refs #20910 -- Replaced snippet directive with code-block.
Backport of c49ea6f5911296dcb40190c905e38b43cdc7c7a3 from master
Diffstat (limited to 'docs/topics')
-rw-r--r--docs/topics/auth/passwords.txt12
-rw-r--r--docs/topics/class-based-views/generic-editing.txt28
-rw-r--r--docs/topics/class-based-views/mixins.txt8
-rw-r--r--docs/topics/db/models.txt4
-rw-r--r--docs/topics/forms/index.txt16
-rw-r--r--docs/topics/http/file-uploads.txt16
-rw-r--r--docs/topics/http/urls.txt16
-rw-r--r--docs/topics/logging.txt4
-rw-r--r--docs/topics/testing/advanced.txt8
9 files changed, 56 insertions, 56 deletions
diff --git a/docs/topics/auth/passwords.txt b/docs/topics/auth/passwords.txt
index 7b72c4292d..fa2fddaa16 100644
--- a/docs/topics/auth/passwords.txt
+++ b/docs/topics/auth/passwords.txt
@@ -251,8 +251,8 @@ modify the pattern to work with any algorithm or with a custom user model.
First, we'll add the custom hasher:
-.. snippet::
- :filename: accounts/hashers.py
+.. code-block:: python
+ :caption: accounts/hashers.py
from django.contrib.auth.hashers import (
PBKDF2PasswordHasher, SHA1PasswordHasher,
@@ -271,8 +271,8 @@ First, we'll add the custom hasher:
The data migration might look something like:
-.. snippet::
- :filename: accounts/migrations/0002_migrate_sha1_passwords.py
+.. code-block:: python
+ :caption: accounts/migrations/0002_migrate_sha1_passwords.py
from django.db import migrations
@@ -306,8 +306,8 @@ several thousand users, depending on the speed of your hardware.
Finally, we'll add a :setting:`PASSWORD_HASHERS` setting:
-.. snippet::
- :filename: mysite/settings.py
+.. code-block:: python
+ :caption: mysite/settings.py
PASSWORD_HASHERS = [
'django.contrib.auth.hashers.PBKDF2PasswordHasher',
diff --git a/docs/topics/class-based-views/generic-editing.txt b/docs/topics/class-based-views/generic-editing.txt
index 15e136939f..a89483ec5a 100644
--- a/docs/topics/class-based-views/generic-editing.txt
+++ b/docs/topics/class-based-views/generic-editing.txt
@@ -18,8 +18,8 @@ Basic forms
Given a simple contact form:
-.. snippet::
- :filename: forms.py
+.. code-block:: python
+ :caption: forms.py
from django import forms
@@ -33,8 +33,8 @@ Given a simple contact form:
The view can be constructed using a ``FormView``:
-.. snippet::
- :filename: views.py
+.. code-block:: python
+ :caption: views.py
from myapp.forms import ContactForm
from django.views.generic.edit import FormView
@@ -96,8 +96,8 @@ add extra validation) simply set
First we need to add :meth:`~django.db.models.Model.get_absolute_url()` to our
``Author`` class:
-.. snippet::
- :filename: models.py
+.. code-block:: python
+ :caption: models.py
from django.db import models
from django.urls import reverse
@@ -112,8 +112,8 @@ Then we can use :class:`CreateView` and friends to do the actual
work. Notice how we're just configuring the generic class-based views
here; we don't have to write any logic ourselves:
-.. snippet::
- :filename: views.py
+.. code-block:: python
+ :caption: views.py
from django.urls import reverse_lazy
from django.views.generic.edit import CreateView, DeleteView, UpdateView
@@ -146,8 +146,8 @@ and :attr:`~django.views.generic.edit.FormMixin.form_class` attributes, an
Finally, we hook these new views into the URLconf:
-.. snippet::
- :filename: urls.py
+.. code-block:: python
+ :caption: urls.py
from django.urls import path
from myapp.views import AuthorCreate, AuthorDelete, AuthorUpdate
@@ -187,8 +187,8 @@ To track the user that created an object using a :class:`CreateView`,
you can use a custom :class:`~django.forms.ModelForm` to do this. First, add
the foreign key relation to the model:
-.. snippet::
- :filename: models.py
+.. code-block:: python
+ :caption: models.py
from django.contrib.auth.models import User
from django.db import models
@@ -203,8 +203,8 @@ In the view, ensure that you don't include ``created_by`` in the list of fields
to edit, and override
:meth:`~django.views.generic.edit.ModelFormMixin.form_valid()` to add the user:
-.. snippet::
- :filename: views.py
+.. code-block:: python
+ :caption: views.py
from django.views.generic.edit import CreateView
from myapp.models import Author
diff --git a/docs/topics/class-based-views/mixins.txt b/docs/topics/class-based-views/mixins.txt
index e066cfcfb5..ac0648df98 100644
--- a/docs/topics/class-based-views/mixins.txt
+++ b/docs/topics/class-based-views/mixins.txt
@@ -222,8 +222,8 @@ we'll want the functionality provided by
We'll demonstrate this with the ``Author`` model we used in the
:doc:`generic class-based views introduction<generic-display>`.
-.. snippet::
- :filename: views.py
+.. code-block:: python
+ :caption: views.py
from django.http import HttpResponseForbidden, HttpResponseRedirect
from django.urls import reverse
@@ -255,8 +255,8 @@ mixin.
We can hook this into our URLs easily enough:
-.. snippet::
- :filename: urls.py
+.. code-block:: python
+ :caption: urls.py
from django.urls import path
from books.views import RecordInterest
diff --git a/docs/topics/db/models.txt b/docs/topics/db/models.txt
index 74ec4dc230..e61b91c81c 100644
--- a/docs/topics/db/models.txt
+++ b/docs/topics/db/models.txt
@@ -1429,8 +1429,8 @@ store your models. You must import the models in the ``__init__.py`` file.
For example, if you had ``organic.py`` and ``synthetic.py`` in the ``models``
directory:
-.. snippet::
- :filename: myapp/models/__init__.py
+.. code-block:: python
+ :caption: myapp/models/__init__.py
from .organic import Person
from .synthetic import Robot
diff --git a/docs/topics/forms/index.txt b/docs/topics/forms/index.txt
index f8ef20a9bc..8340c0f096 100644
--- a/docs/topics/forms/index.txt
+++ b/docs/topics/forms/index.txt
@@ -226,8 +226,8 @@ The :class:`Form` class
We already know what we want our HTML form to look like. Our starting point for
it in Django is this:
-.. snippet::
- :filename: forms.py
+.. code-block:: python
+ :caption: forms.py
from django import forms
@@ -276,8 +276,8 @@ logic.
To handle the form we need to instantiate it in the view for the URL where we
want it to be published:
-.. snippet::
- :filename: views.py
+.. code-block:: python
+ :caption: views.py
from django.http import HttpResponseRedirect
from django.shortcuts import render
@@ -404,8 +404,8 @@ More on fields
Consider a more useful form than our minimal example above, which we could use
to implement "contact me" functionality on a personal website:
-.. snippet::
- :filename: forms.py
+.. code-block:: python
+ :caption: forms.py
from django import forms
@@ -453,8 +453,8 @@ values to a Python ``int`` and ``float`` respectively.
Here's how the form data could be processed in the view that handles this form:
-.. snippet::
- :filename: views.py
+.. code-block:: python
+ :caption: views.py
from django.core.mail import send_mail
diff --git a/docs/topics/http/file-uploads.txt b/docs/topics/http/file-uploads.txt
index 46ebf2e52a..21a6f06853 100644
--- a/docs/topics/http/file-uploads.txt
+++ b/docs/topics/http/file-uploads.txt
@@ -21,8 +21,8 @@ Basic file uploads
Consider a simple form containing a :class:`~django.forms.FileField`:
-.. snippet::
- :filename: forms.py
+.. code-block:: python
+ :caption: forms.py
from django import forms
@@ -46,8 +46,8 @@ Most of the time, you'll simply pass the file data from ``request`` into the
form as described in :ref:`binding-uploaded-files`. This would look
something like:
-.. snippet::
- :filename: views.py
+.. code-block:: python
+ :caption: views.py
from django.http import HttpResponseRedirect
from django.shortcuts import render
@@ -133,8 +133,8 @@ Uploading multiple files
If you want to upload multiple files using one form field, set the ``multiple``
HTML attribute of field's widget:
-.. snippet::
- :filename: forms.py
+.. code-block:: python
+ :caption: forms.py
from django import forms
@@ -145,8 +145,8 @@ Then override the ``post`` method of your
:class:`~django.views.generic.edit.FormView` subclass to handle multiple file
uploads:
-.. snippet::
- :filename: views.py
+.. code-block:: python
+ :caption: views.py
from django.views.generic.edit import FormView
from .forms import FileFieldForm
diff --git a/docs/topics/http/urls.txt b/docs/topics/http/urls.txt
index 4ee7a4e9ba..50d63e9a88 100644
--- a/docs/topics/http/urls.txt
+++ b/docs/topics/http/urls.txt
@@ -761,8 +761,8 @@ and one called ``'publisher-polls'``. Assume we have enhanced that application
so that it takes the instance namespace into consideration when creating and
displaying polls.
-.. snippet::
- :filename: urls.py
+.. code-block:: python
+ :caption: urls.py
from django.urls import include, path
@@ -771,8 +771,8 @@ displaying polls.
path('publisher-polls/', include('polls.urls', namespace='publisher-polls')),
]
-.. snippet::
- :filename: polls/urls.py
+.. code-block:: python
+ :caption: polls/urls.py
from django.urls import path
@@ -830,8 +830,8 @@ at the same level as the ``urlpatterns`` attribute. You have to pass the actual
module, or a string reference to the module, to :func:`~django.urls.include`,
not the list of ``urlpatterns`` itself.
-.. snippet::
- :filename: polls/urls.py
+.. code-block:: python
+ :caption: polls/urls.py
from django.urls import path
@@ -844,8 +844,8 @@ not the list of ``urlpatterns`` itself.
...
]
-.. snippet::
- :filename: urls.py
+.. code-block:: python
+ :caption: urls.py
from django.urls import include, path
diff --git a/docs/topics/logging.txt b/docs/topics/logging.txt
index 5772df0341..0e0700c618 100644
--- a/docs/topics/logging.txt
+++ b/docs/topics/logging.txt
@@ -429,8 +429,8 @@ configuration process for :ref:`Django's default logging
<default-logging-configuration>`. Here's an example that disables Django's
logging configuration and then manually configures logging:
-.. snippet::
- :filename: settings.py
+.. code-block:: python
+ :caption: settings.py
LOGGING_CONFIG = None
diff --git a/docs/topics/testing/advanced.txt b/docs/topics/testing/advanced.txt
index 7e65a896f2..455c121acd 100644
--- a/docs/topics/testing/advanced.txt
+++ b/docs/topics/testing/advanced.txt
@@ -325,8 +325,8 @@ following structure::
Let's take a look inside a couple of those files:
-.. snippet::
- :filename: runtests.py
+.. code-block:: python
+ :caption: runtests.py
#!/usr/bin/env python
import os
@@ -353,8 +353,8 @@ necessary to use the Django test runner. You may want to add
command-line options for controlling verbosity, passing in specific test
labels to run, etc.
-.. snippet::
- :filename: tests/test_settings.py
+.. code-block:: python
+ :caption: tests/test_settings.py
SECRET_KEY = 'fake-key'
INSTALLED_APPS = [