mirror of
https://github.com/django/django.git
synced 2024-12-22 00:55:44 +00:00
Fixed docs build with sphinxcontrib-spelling 7.5.0+.
sphinxcontrib-spelling 7.5.0+ includes captions of figures in the set of nodes for which the text is checked.
This commit is contained in:
parent
1058fc7023
commit
ac90529cc5
1
docs/_theme/djangodocs/static/djangodocs.css
vendored
1
docs/_theme/djangodocs/static/djangodocs.css
vendored
@ -103,6 +103,7 @@ dt .literal, table .literal { background:none; }
|
||||
#bd a.reference { text-decoration: none; }
|
||||
#bd a.reference tt.literal { border-bottom: 1px #234f32 dotted; }
|
||||
div.code-block-caption { color: white; background-color: #234F32; margin: 0; padding: 2px 5px; width: 100%; font-family: monospace; font-size: small; line-height: 1.3em; }
|
||||
div.code-block-caption .literal {color: white; }
|
||||
div.literal-block-wrapper pre { margin-top: 0; }
|
||||
|
||||
/* Restore colors of pygments hyperlinked code */
|
||||
|
@ -112,7 +112,7 @@ For example, you can use this technique to add a custom logo to the
|
||||
``admin/base_site.html`` template:
|
||||
|
||||
.. code-block:: html+django
|
||||
:caption: templates/admin/base_site.html
|
||||
:caption: ``templates/admin/base_site.html``
|
||||
|
||||
{% extends "admin/base_site.html" %}
|
||||
|
||||
|
@ -40,7 +40,7 @@ You can also provide hints that will be passed to the :meth:`allow_migrate()`
|
||||
method of database routers as ``**hints``:
|
||||
|
||||
.. code-block:: python
|
||||
:caption: myapp/dbrouters.py
|
||||
:caption: ``myapp/dbrouters.py``
|
||||
|
||||
class MyRouter:
|
||||
|
||||
@ -98,7 +98,7 @@ the respective field according to your needs.
|
||||
``AlterField``, and add imports of ``uuid`` and ``models``. For example:
|
||||
|
||||
.. code-block:: python
|
||||
:caption: 0006_remove_uuid_null.py
|
||||
:caption: ``0006_remove_uuid_null.py``
|
||||
|
||||
# Generated by Django A.B on YYYY-MM-DD HH:MM
|
||||
from django.db import migrations, models
|
||||
@ -122,7 +122,7 @@ the respective field according to your needs.
|
||||
similar to this:
|
||||
|
||||
.. code-block:: python
|
||||
:caption: 0004_add_uuid_field.py
|
||||
:caption: ``0004_add_uuid_field.py``
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
@ -149,7 +149,7 @@ the respective field according to your needs.
|
||||
of ``uuid``. For example:
|
||||
|
||||
.. code-block:: python
|
||||
:caption: 0005_populate_uuid_values.py
|
||||
:caption: ``0005_populate_uuid_values.py``
|
||||
|
||||
# Generated by Django A.B on YYYY-MM-DD HH:MM
|
||||
from django.db import migrations
|
||||
@ -283,7 +283,7 @@ project anywhere without first installing and then uninstalling the old app.
|
||||
Here's a sample migration:
|
||||
|
||||
.. code-block:: python
|
||||
:caption: myapp/migrations/0124_move_old_app_to_new_app.py
|
||||
:caption: ``myapp/migrations/0124_move_old_app_to_new_app.py``
|
||||
|
||||
from django.apps import apps as global_apps
|
||||
from django.db import migrations
|
||||
|
@ -167,7 +167,7 @@ Imports
|
||||
For example (comments are for explanatory purposes only):
|
||||
|
||||
.. code-block:: python
|
||||
:caption: django/contrib/admin/example.py
|
||||
:caption: ``django/contrib/admin/example.py``
|
||||
|
||||
# future
|
||||
from __future__ import unicode_literals
|
||||
|
@ -564,7 +564,7 @@ Since this pattern involves a lot of boilerplate, Django provides the
|
||||
installed, you should pass the set of targeted ``app_label`` as arguments:
|
||||
|
||||
.. code-block:: python
|
||||
:caption: tests/app_label/tests.py
|
||||
:caption: ``tests/app_label/tests.py``
|
||||
|
||||
from django.db import models
|
||||
from django.test import SimpleTestCase
|
||||
|
@ -63,7 +63,7 @@ You'll need a few things before getting started:
|
||||
* Access to Django's record on PyPI. Create a file with your credentials:
|
||||
|
||||
.. code-block:: ini
|
||||
:caption: ~/.pypirc
|
||||
:caption: ``~/.pypirc``
|
||||
|
||||
[pypi]
|
||||
username:YourUsername
|
||||
|
@ -26,7 +26,7 @@ representing your models -- so far, it's been solving many years' worth of
|
||||
database-schema problems. Here's a quick example:
|
||||
|
||||
.. code-block:: python
|
||||
:caption: mysite/news/models.py
|
||||
:caption: ``mysite/news/models.py``
|
||||
|
||||
from django.db import models
|
||||
|
||||
@ -146,7 +146,7 @@ a website that lets authenticated users add, change and delete objects. The
|
||||
only step required is to register your model in the admin site:
|
||||
|
||||
.. code-block:: python
|
||||
:caption: mysite/news/models.py
|
||||
:caption: ``mysite/news/models.py``
|
||||
|
||||
from django.db import models
|
||||
|
||||
@ -157,7 +157,7 @@ only step required is to register your model in the admin site:
|
||||
reporter = models.ForeignKey(Reporter, on_delete=models.CASCADE)
|
||||
|
||||
.. code-block:: python
|
||||
:caption: mysite/news/admin.py
|
||||
:caption: ``mysite/news/admin.py``
|
||||
|
||||
from django.contrib import admin
|
||||
|
||||
@ -189,7 +189,7 @@ Here's what a URLconf might look like for the ``Reporter``/``Article``
|
||||
example above:
|
||||
|
||||
.. code-block:: python
|
||||
:caption: mysite/news/urls.py
|
||||
:caption: ``mysite/news/urls.py``
|
||||
|
||||
from django.urls import path
|
||||
|
||||
@ -229,7 +229,7 @@ and renders the template with the retrieved data. Here's an example view for
|
||||
``year_archive`` from above:
|
||||
|
||||
.. code-block:: python
|
||||
:caption: mysite/news/views.py
|
||||
:caption: ``mysite/news/views.py``
|
||||
|
||||
from django.shortcuts import render
|
||||
|
||||
@ -258,7 +258,7 @@ Let's say the ``news/year_archive.html`` template was found. Here's what that
|
||||
might look like:
|
||||
|
||||
.. code-block:: html+django
|
||||
:caption: mysite/news/templates/news/year_archive.html
|
||||
:caption: ``mysite/news/templates/news/year_archive.html``
|
||||
|
||||
{% extends "base.html" %}
|
||||
|
||||
@ -299,7 +299,7 @@ Here's what the "base.html" template, including the use of :doc:`static files
|
||||
</howto/static-files/index>`, might look like:
|
||||
|
||||
.. code-block:: html+django
|
||||
:caption: mysite/templates/base.html
|
||||
:caption: ``mysite/templates/base.html``
|
||||
|
||||
{% load static %}
|
||||
<html>
|
||||
|
@ -144,7 +144,7 @@ this. For a small app like polls, this process isn't too difficult.
|
||||
#. Create a file ``django-polls/README.rst`` with the following contents:
|
||||
|
||||
.. code-block:: rst
|
||||
:caption: django-polls/README.rst
|
||||
:caption: ``django-polls/README.rst``
|
||||
|
||||
=====
|
||||
Polls
|
||||
@ -192,14 +192,14 @@ this. For a small app like polls, this process isn't too difficult.
|
||||
following contents:
|
||||
|
||||
.. code-block:: toml
|
||||
:caption: django-polls/pyproject.toml
|
||||
:caption: ``django-polls/pyproject.toml``
|
||||
|
||||
[build-system]
|
||||
requires = ['setuptools>=40.8.0', 'wheel']
|
||||
build-backend = 'setuptools.build_meta:__legacy__'
|
||||
|
||||
.. code-block:: ini
|
||||
:caption: django-polls/setup.cfg
|
||||
:caption: ``django-polls/setup.cfg``
|
||||
|
||||
[metadata]
|
||||
name = django-polls
|
||||
@ -233,7 +233,7 @@ this. For a small app like polls, this process isn't too difficult.
|
||||
Django >= X.Y # Replace "X.Y" as appropriate
|
||||
|
||||
.. code-block:: python
|
||||
:caption: django-polls/setup.py
|
||||
:caption: ``django-polls/setup.py``
|
||||
|
||||
from setuptools import setup
|
||||
|
||||
@ -247,7 +247,7 @@ this. For a small app like polls, this process isn't too difficult.
|
||||
contents:
|
||||
|
||||
.. code-block:: text
|
||||
:caption: django-polls/MANIFEST.in
|
||||
:caption: ``django-polls/MANIFEST.in``
|
||||
|
||||
include LICENSE
|
||||
include README.rst
|
||||
|
@ -245,7 +245,7 @@ Let's write the first view. Open the file ``polls/views.py``
|
||||
and put the following Python code in it:
|
||||
|
||||
.. code-block:: python
|
||||
:caption: polls/views.py
|
||||
:caption: ``polls/views.py``
|
||||
|
||||
from django.http import HttpResponse
|
||||
|
||||
@ -273,7 +273,7 @@ Your app directory should now look like::
|
||||
In the ``polls/urls.py`` file include the following code:
|
||||
|
||||
.. code-block:: python
|
||||
:caption: polls/urls.py
|
||||
:caption: ``polls/urls.py``
|
||||
|
||||
from django.urls import path
|
||||
|
||||
@ -288,7 +288,7 @@ The next step is to point the root URLconf at the ``polls.urls`` module. In
|
||||
:func:`~django.urls.include` in the ``urlpatterns`` list, so you have:
|
||||
|
||||
.. code-block:: python
|
||||
:caption: mysite/urls.py
|
||||
:caption: ``mysite/urls.py``
|
||||
|
||||
from django.contrib import admin
|
||||
from django.urls import include, path
|
||||
|
@ -141,7 +141,7 @@ These concepts are represented by Python classes. Edit the
|
||||
:file:`polls/models.py` file so it looks like this:
|
||||
|
||||
.. code-block:: python
|
||||
:caption: polls/models.py
|
||||
:caption: ``polls/models.py``
|
||||
|
||||
from django.db import models
|
||||
|
||||
@ -217,7 +217,7 @@ add that dotted path to the :setting:`INSTALLED_APPS` setting. It'll look like
|
||||
this:
|
||||
|
||||
.. code-block:: python
|
||||
:caption: mysite/settings.py
|
||||
:caption: ``mysite/settings.py``
|
||||
|
||||
INSTALLED_APPS = [
|
||||
'polls.apps.PollsConfig',
|
||||
@ -424,7 +424,7 @@ representation of this object. Let's fix that by editing the ``Question`` model
|
||||
``Choice``:
|
||||
|
||||
.. code-block:: python
|
||||
:caption: polls/models.py
|
||||
:caption: ``polls/models.py``
|
||||
|
||||
from django.db import models
|
||||
|
||||
@ -448,7 +448,7 @@ automatically-generated admin.
|
||||
Let's also add a custom method to this model:
|
||||
|
||||
.. code-block:: python
|
||||
:caption: polls/models.py
|
||||
:caption: ``polls/models.py``
|
||||
|
||||
import datetime
|
||||
|
||||
@ -646,7 +646,7 @@ have an admin interface. To do this, open the :file:`polls/admin.py` file, and
|
||||
edit it to look like this:
|
||||
|
||||
.. code-block:: python
|
||||
:caption: polls/admin.py
|
||||
:caption: ``polls/admin.py``
|
||||
|
||||
from django.contrib import admin
|
||||
|
||||
|
@ -70,7 +70,7 @@ Now let's add a few more views to ``polls/views.py``. These views are
|
||||
slightly different, because they take an argument:
|
||||
|
||||
.. code-block:: python
|
||||
:caption: polls/views.py
|
||||
:caption: ``polls/views.py``
|
||||
|
||||
def detail(request, question_id):
|
||||
return HttpResponse("You're looking at question %s." % question_id)
|
||||
@ -86,7 +86,7 @@ Wire these new views into the ``polls.urls`` module by adding the following
|
||||
:func:`~django.urls.path` calls:
|
||||
|
||||
.. code-block:: python
|
||||
:caption: polls/urls.py
|
||||
:caption: ``polls/urls.py``
|
||||
|
||||
from django.urls import path
|
||||
|
||||
@ -147,7 +147,7 @@ view, which displays the latest 5 poll questions in the system, separated by
|
||||
commas, according to publication date:
|
||||
|
||||
.. code-block:: python
|
||||
:caption: polls/views.py
|
||||
:caption: ``polls/views.py``
|
||||
|
||||
from django.http import HttpResponse
|
||||
|
||||
@ -196,7 +196,7 @@ Django as ``polls/index.html``.
|
||||
Put the following code in that template:
|
||||
|
||||
.. code-block:: html+django
|
||||
:caption: polls/templates/polls/index.html
|
||||
:caption: ``polls/templates/polls/index.html``
|
||||
|
||||
{% if latest_question_list %}
|
||||
<ul>
|
||||
@ -218,7 +218,7 @@ __ https://developer.mozilla.org/en-US/docs/Learn/HTML/Introduction_to_HTML/Gett
|
||||
Now let's update our ``index`` view in ``polls/views.py`` to use the template:
|
||||
|
||||
.. code-block:: python
|
||||
:caption: polls/views.py
|
||||
:caption: ``polls/views.py``
|
||||
|
||||
from django.http import HttpResponse
|
||||
from django.template import loader
|
||||
@ -251,7 +251,7 @@ template. Django provides a shortcut. Here's the full ``index()`` view,
|
||||
rewritten:
|
||||
|
||||
.. code-block:: python
|
||||
:caption: polls/views.py
|
||||
:caption: ``polls/views.py``
|
||||
|
||||
from django.shortcuts import render
|
||||
|
||||
@ -280,7 +280,7 @@ Now, let's tackle the question detail view -- the page that displays the questio
|
||||
for a given poll. Here's the view:
|
||||
|
||||
.. code-block:: python
|
||||
:caption: polls/views.py
|
||||
:caption: ``polls/views.py``
|
||||
|
||||
from django.http import Http404
|
||||
from django.shortcuts import render
|
||||
@ -302,7 +302,7 @@ later, but if you'd like to quickly get the above example working, a file
|
||||
containing just:
|
||||
|
||||
.. code-block:: html+django
|
||||
:caption: polls/templates/polls/detail.html
|
||||
:caption: ``polls/templates/polls/detail.html``
|
||||
|
||||
{{ question }}
|
||||
|
||||
@ -316,7 +316,7 @@ and raise :exc:`~django.http.Http404` if the object doesn't exist. Django
|
||||
provides a shortcut. Here's the ``detail()`` view, rewritten:
|
||||
|
||||
.. code-block:: python
|
||||
:caption: polls/views.py
|
||||
:caption: ``polls/views.py``
|
||||
|
||||
from django.shortcuts import get_object_or_404, render
|
||||
|
||||
@ -358,7 +358,7 @@ variable ``question``, here's what the ``polls/detail.html`` template might look
|
||||
like:
|
||||
|
||||
.. code-block:: html+django
|
||||
:caption: polls/templates/polls/detail.html
|
||||
:caption: ``polls/templates/polls/detail.html``
|
||||
|
||||
<h1>{{ question.question_text }}</h1>
|
||||
<ul>
|
||||
@ -432,7 +432,7 @@ The answer is to add namespaces to your URLconf. In the ``polls/urls.py``
|
||||
file, go ahead and add an ``app_name`` to set the application namespace:
|
||||
|
||||
.. code-block:: python
|
||||
:caption: polls/urls.py
|
||||
:caption: ``polls/urls.py``
|
||||
|
||||
from django.urls import path
|
||||
|
||||
@ -449,14 +449,14 @@ file, go ahead and add an ``app_name`` to set the application namespace:
|
||||
Now change your ``polls/index.html`` template from:
|
||||
|
||||
.. code-block:: html+django
|
||||
:caption: polls/templates/polls/index.html
|
||||
:caption: ``polls/templates/polls/index.html``
|
||||
|
||||
<li><a href="{% url 'detail' question.id %}">{{ question.question_text }}</a></li>
|
||||
|
||||
to point at the namespaced detail view:
|
||||
|
||||
.. code-block:: html+django
|
||||
:caption: polls/templates/polls/index.html
|
||||
:caption: ``polls/templates/polls/index.html``
|
||||
|
||||
<li><a href="{% url 'polls:detail' question.id %}">{{ question.question_text }}</a></li>
|
||||
|
||||
|
@ -18,7 +18,7 @@ Let's update our poll detail template ("polls/detail.html") from the last
|
||||
tutorial, so that the template contains an HTML ``<form>`` element:
|
||||
|
||||
.. code-block:: html+django
|
||||
:caption: polls/templates/polls/detail.html
|
||||
:caption: ``polls/templates/polls/detail.html``
|
||||
|
||||
<form action="{% url 'polls:vote' question.id %}" method="post">
|
||||
{% csrf_token %}
|
||||
@ -64,7 +64,7 @@ something with it. Remember, in :doc:`Tutorial 3 </intro/tutorial03>`, we
|
||||
created a URLconf for the polls application that includes this line:
|
||||
|
||||
.. code-block:: python
|
||||
:caption: polls/urls.py
|
||||
:caption: ``polls/urls.py``
|
||||
|
||||
path('<int:question_id>/vote/', views.vote, name='vote'),
|
||||
|
||||
@ -72,7 +72,7 @@ We also created a dummy implementation of the ``vote()`` function. Let's
|
||||
create a real version. Add the following to ``polls/views.py``:
|
||||
|
||||
.. code-block:: python
|
||||
:caption: polls/views.py
|
||||
:caption: ``polls/views.py``
|
||||
|
||||
from django.http import HttpResponse, HttpResponseRedirect
|
||||
from django.shortcuts import get_object_or_404, render
|
||||
@ -152,7 +152,7 @@ After somebody votes in a question, the ``vote()`` view redirects to the results
|
||||
page for the question. Let's write that view:
|
||||
|
||||
.. code-block:: python
|
||||
:caption: polls/views.py
|
||||
:caption: ``polls/views.py``
|
||||
|
||||
from django.shortcuts import get_object_or_404, render
|
||||
|
||||
@ -168,7 +168,7 @@ redundancy later.
|
||||
Now, create a ``polls/results.html`` template:
|
||||
|
||||
.. code-block:: html+django
|
||||
:caption: polls/templates/polls/results.html
|
||||
:caption: ``polls/templates/polls/results.html``
|
||||
|
||||
<h1>{{ question.question_text }}</h1>
|
||||
|
||||
@ -240,7 +240,7 @@ Amend URLconf
|
||||
First, open the ``polls/urls.py`` URLconf and change it like so:
|
||||
|
||||
.. code-block:: python
|
||||
:caption: polls/urls.py
|
||||
:caption: ``polls/urls.py``
|
||||
|
||||
from django.urls import path
|
||||
|
||||
@ -265,7 +265,7 @@ views and use Django's generic views instead. To do so, open the
|
||||
``polls/views.py`` file and change it like so:
|
||||
|
||||
.. code-block:: python
|
||||
:caption: polls/views.py
|
||||
:caption: ``polls/views.py``
|
||||
|
||||
from django.http import HttpResponseRedirect
|
||||
from django.shortcuts import get_object_or_404, render
|
||||
|
@ -172,7 +172,7 @@ whose name begins with ``test``.
|
||||
Put the following in the ``tests.py`` file in the ``polls`` application:
|
||||
|
||||
.. code-block:: python
|
||||
:caption: polls/tests.py
|
||||
:caption: ``polls/tests.py``
|
||||
|
||||
import datetime
|
||||
|
||||
@ -261,7 +261,7 @@ return ``False`` if its ``pub_date`` is in the future. Amend the method in
|
||||
past:
|
||||
|
||||
.. code-block:: python
|
||||
:caption: polls/models.py
|
||||
:caption: ``polls/models.py``
|
||||
|
||||
def was_published_recently(self):
|
||||
now = timezone.now()
|
||||
@ -297,7 +297,7 @@ Add two more test methods to the same class, to test the behavior of the method
|
||||
more comprehensively:
|
||||
|
||||
.. code-block:: python
|
||||
:caption: polls/tests.py
|
||||
:caption: ``polls/tests.py``
|
||||
|
||||
def test_was_published_recently_with_old_question(self):
|
||||
"""
|
||||
@ -413,7 +413,7 @@ In :doc:`Tutorial 4 </intro/tutorial04>` we introduced a class-based view,
|
||||
based on :class:`~django.views.generic.list.ListView`:
|
||||
|
||||
.. code-block:: python
|
||||
:caption: polls/views.py
|
||||
:caption: ``polls/views.py``
|
||||
|
||||
class IndexView(generic.ListView):
|
||||
template_name = 'polls/index.html'
|
||||
@ -428,14 +428,14 @@ checks the date by comparing it with ``timezone.now()``. First we need to add
|
||||
an import:
|
||||
|
||||
.. code-block:: python
|
||||
:caption: polls/views.py
|
||||
:caption: ``polls/views.py``
|
||||
|
||||
from django.utils import timezone
|
||||
|
||||
and then we must amend the ``get_queryset`` method like so:
|
||||
|
||||
.. code-block:: python
|
||||
:caption: polls/views.py
|
||||
:caption: ``polls/views.py``
|
||||
|
||||
def get_queryset(self):
|
||||
"""
|
||||
@ -463,7 +463,7 @@ our :djadmin:`shell` session above.
|
||||
Add the following to ``polls/tests.py``:
|
||||
|
||||
.. code-block:: python
|
||||
:caption: polls/tests.py
|
||||
:caption: ``polls/tests.py``
|
||||
|
||||
from django.urls import reverse
|
||||
|
||||
@ -471,7 +471,7 @@ and we'll create a shortcut function to create questions as well as a new test
|
||||
class:
|
||||
|
||||
.. code-block:: python
|
||||
:caption: polls/tests.py
|
||||
:caption: ``polls/tests.py``
|
||||
|
||||
def create_question(question_text, days):
|
||||
"""
|
||||
@ -572,7 +572,7 @@ the *index*, users can still reach them if they know or guess the right URL. So
|
||||
we need to add a similar constraint to ``DetailView``:
|
||||
|
||||
.. code-block:: python
|
||||
:caption: polls/views.py
|
||||
:caption: ``polls/views.py``
|
||||
|
||||
class DetailView(generic.DetailView):
|
||||
...
|
||||
@ -587,7 +587,7 @@ is in the past can be displayed, and that one with a ``pub_date`` in the future
|
||||
is not:
|
||||
|
||||
.. code-block:: python
|
||||
:caption: polls/tests.py
|
||||
:caption: ``polls/tests.py``
|
||||
|
||||
class QuestionDetailViewTests(TestCase):
|
||||
def test_future_question(self):
|
||||
|
@ -61,7 +61,7 @@ the path for templates.
|
||||
Put the following code in that stylesheet (``polls/static/polls/style.css``):
|
||||
|
||||
.. code-block:: css
|
||||
:caption: polls/static/polls/style.css
|
||||
:caption: ``polls/static/polls/style.css``
|
||||
|
||||
li a {
|
||||
color: green;
|
||||
@ -70,7 +70,7 @@ Put the following code in that stylesheet (``polls/static/polls/style.css``):
|
||||
Next, add the following at the top of ``polls/templates/polls/index.html``:
|
||||
|
||||
.. code-block:: html+django
|
||||
:caption: polls/templates/polls/index.html
|
||||
:caption: ``polls/templates/polls/index.html``
|
||||
|
||||
{% load static %}
|
||||
|
||||
@ -103,7 +103,7 @@ Then, add a reference to your image in your stylesheet
|
||||
(``polls/static/polls/style.css``):
|
||||
|
||||
.. code-block:: css
|
||||
:caption: polls/static/polls/style.css
|
||||
:caption: ``polls/static/polls/style.css``
|
||||
|
||||
body {
|
||||
background: white url("images/background.png") no-repeat;
|
||||
|
@ -24,7 +24,7 @@ Let's see how this works by reordering the fields on the edit form. Replace
|
||||
the ``admin.site.register(Question)`` line with:
|
||||
|
||||
.. code-block:: python
|
||||
:caption: polls/admin.py
|
||||
:caption: ``polls/admin.py``
|
||||
|
||||
from django.contrib import admin
|
||||
|
||||
@ -53,7 +53,7 @@ And speaking of forms with dozens of fields, you might want to split the form
|
||||
up into fieldsets:
|
||||
|
||||
.. code-block:: python
|
||||
:caption: polls/admin.py
|
||||
:caption: ``polls/admin.py``
|
||||
|
||||
from django.contrib import admin
|
||||
|
||||
@ -87,7 +87,7 @@ There are two ways to solve this problem. The first is to register ``Choice``
|
||||
with the admin just as we did with ``Question``:
|
||||
|
||||
.. code-block:: python
|
||||
:caption: polls/admin.py
|
||||
:caption: ``polls/admin.py``
|
||||
|
||||
from django.contrib import admin
|
||||
|
||||
@ -121,7 +121,7 @@ Remove the ``register()`` call for the ``Choice`` model. Then, edit the ``Questi
|
||||
registration code to read:
|
||||
|
||||
.. code-block:: python
|
||||
:caption: polls/admin.py
|
||||
:caption: ``polls/admin.py``
|
||||
|
||||
from django.contrib import admin
|
||||
|
||||
@ -168,7 +168,7 @@ tabular way of displaying inline related objects. To use it, change the
|
||||
``ChoiceInline`` declaration to read:
|
||||
|
||||
.. code-block:: python
|
||||
:caption: polls/admin.py
|
||||
:caption: ``polls/admin.py``
|
||||
|
||||
class ChoiceInline(admin.TabularInline):
|
||||
#...
|
||||
@ -200,7 +200,7 @@ tuple of field names to display, as columns, on the change list page for the
|
||||
object:
|
||||
|
||||
.. code-block:: python
|
||||
:caption: polls/admin.py
|
||||
:caption: ``polls/admin.py``
|
||||
|
||||
class QuestionAdmin(admin.ModelAdmin):
|
||||
# ...
|
||||
@ -210,7 +210,7 @@ For good measure, let's also include the ``was_published_recently()`` method
|
||||
from :doc:`Tutorial 2 </intro/tutorial02>`:
|
||||
|
||||
.. code-block:: python
|
||||
:caption: polls/admin.py
|
||||
:caption: ``polls/admin.py``
|
||||
|
||||
class QuestionAdmin(admin.ModelAdmin):
|
||||
# ...
|
||||
@ -232,7 +232,7 @@ You can improve that by using the :func:`~django.contrib.admin.display`
|
||||
decorator on that method (in :file:`polls/models.py`), as follows:
|
||||
|
||||
.. code-block:: python
|
||||
:caption: polls/models.py
|
||||
:caption: ``polls/models.py``
|
||||
|
||||
from django.contrib import admin
|
||||
|
||||
@ -310,7 +310,7 @@ Open your settings file (:file:`mysite/settings.py`, remember) and add a
|
||||
:setting:`DIRS <TEMPLATES-DIRS>` option in the :setting:`TEMPLATES` setting:
|
||||
|
||||
.. code-block:: python
|
||||
:caption: mysite/settings.py
|
||||
:caption: ``mysite/settings.py``
|
||||
|
||||
TEMPLATES = [
|
||||
{
|
||||
|
@ -2977,7 +2977,7 @@ it instead of with the default site. Finally, update :file:`myproject/urls.py`
|
||||
to reference your :class:`AdminSite` subclass.
|
||||
|
||||
.. code-block:: python
|
||||
:caption: myapp/admin.py
|
||||
:caption: ``myapp/admin.py``
|
||||
|
||||
from django.contrib import admin
|
||||
|
||||
@ -2991,7 +2991,7 @@ to reference your :class:`AdminSite` subclass.
|
||||
|
||||
|
||||
.. code-block:: python
|
||||
:caption: myproject/urls.py
|
||||
:caption: ``myproject/urls.py``
|
||||
|
||||
from django.urls import path
|
||||
|
||||
@ -3018,7 +3018,7 @@ to the dotted import path of either a ``AdminSite`` subclass or a callable that
|
||||
returns a site instance.
|
||||
|
||||
.. code-block:: python
|
||||
:caption: myproject/admin.py
|
||||
:caption: ``myproject/admin.py``
|
||||
|
||||
from django.contrib import admin
|
||||
|
||||
@ -3026,7 +3026,7 @@ returns a site instance.
|
||||
...
|
||||
|
||||
.. code-block:: python
|
||||
:caption: myproject/apps.py
|
||||
:caption: ``myproject/apps.py``
|
||||
|
||||
from django.contrib.admin.apps import AdminConfig
|
||||
|
||||
@ -3034,7 +3034,7 @@ returns a site instance.
|
||||
default_site = 'myproject.admin.MyAdminSite'
|
||||
|
||||
.. code-block:: python
|
||||
:caption: myproject/settings.py
|
||||
:caption: ``myproject/settings.py``
|
||||
|
||||
INSTALLED_APPS = [
|
||||
...
|
||||
|
@ -32,7 +32,7 @@ In your custom ``change_form.html`` template, extend the
|
||||
{% endblock %}
|
||||
|
||||
.. code-block:: javascript
|
||||
:caption: app/static/app/formset_handlers.js
|
||||
:caption: ``app/static/app/formset_handlers.js``
|
||||
|
||||
document.addEventListener('formset:added', (event) => {
|
||||
if (event.detail.formsetName == 'author_set') {
|
||||
|
@ -131,7 +131,7 @@ password from the `password file`_, you must specify them in the
|
||||
:setting:`OPTIONS` part of your database configuration in :setting:`DATABASES`:
|
||||
|
||||
.. code-block:: python
|
||||
:caption: settings.py
|
||||
:caption: ``settings.py``
|
||||
|
||||
DATABASES = {
|
||||
'default': {
|
||||
@ -144,7 +144,7 @@ password from the `password file`_, you must specify them in the
|
||||
}
|
||||
|
||||
.. code-block:: text
|
||||
:caption: .pg_service.conf
|
||||
:caption: ``.pg_service.conf``
|
||||
|
||||
[my_service]
|
||||
host=localhost
|
||||
@ -153,7 +153,7 @@ password from the `password file`_, you must specify them in the
|
||||
port=5432
|
||||
|
||||
.. code-block:: text
|
||||
:caption: .my_pgpass
|
||||
:caption: ``.my_pgpass``
|
||||
|
||||
localhost:5432:NAME:USER:PASSWORD
|
||||
|
||||
@ -1081,7 +1081,7 @@ example of subclassing the PostgreSQL engine to change a feature class
|
||||
``allows_group_by_selected_pks_on_model``:
|
||||
|
||||
.. code-block:: python
|
||||
:caption: mysite/mydbengine/base.py
|
||||
:caption: ``mysite/mydbengine/base.py``
|
||||
|
||||
from django.db.backends.postgresql import base, features
|
||||
|
||||
|
@ -331,7 +331,7 @@ The ``Func`` API is as follows:
|
||||
customize the SQL as needed. For example:
|
||||
|
||||
.. code-block:: python
|
||||
:caption: django/db/models/functions.py
|
||||
:caption: ``django/db/models/functions.py``
|
||||
|
||||
class ConcatPair(Func):
|
||||
...
|
||||
|
@ -1458,7 +1458,7 @@ Relationships defined this way on :ref:`abstract models
|
||||
concrete model and are not relative to the abstract model's ``app_label``:
|
||||
|
||||
.. code-block:: python
|
||||
:caption: products/models.py
|
||||
:caption: ``products/models.py``
|
||||
|
||||
from django.db import models
|
||||
|
||||
@ -1469,7 +1469,7 @@ concrete model and are not relative to the abstract model's ``app_label``:
|
||||
abstract = True
|
||||
|
||||
.. code-block:: python
|
||||
:caption: production/models.py
|
||||
:caption: ``production/models.py``
|
||||
|
||||
from django.db import models
|
||||
from products.models import AbstractCar
|
||||
|
@ -564,7 +564,7 @@ current one as well as templates included via the :ttag:`include` tag,
|
||||
just like all block tags. For example:
|
||||
|
||||
.. code-block:: html+django
|
||||
:caption: base.html
|
||||
:caption: ``base.html``
|
||||
|
||||
{% autoescape off %}
|
||||
<h1>{% block title %}{% endblock %}</h1>
|
||||
@ -573,7 +573,7 @@ just like all block tags. For example:
|
||||
{% endautoescape %}
|
||||
|
||||
.. code-block:: html+django
|
||||
:caption: child.html
|
||||
:caption: ``child.html``
|
||||
|
||||
{% extends "base.html" %}
|
||||
{% block title %}This & that{% endblock %}
|
||||
@ -653,14 +653,14 @@ of all comments related to the current task with::
|
||||
You can also access methods you've explicitly defined on your own models:
|
||||
|
||||
.. code-block:: python
|
||||
:caption: models.py
|
||||
:caption: ``models.py``
|
||||
|
||||
class Task(models.Model):
|
||||
def foo(self):
|
||||
return "bar"
|
||||
|
||||
.. code-block:: html+django
|
||||
:caption: template.html
|
||||
:caption: ``template.html``
|
||||
|
||||
{{ task.foo }}
|
||||
|
||||
|
@ -1264,7 +1264,7 @@ attribute (as below). If the ``app_name`` is set in this new way, the
|
||||
``app_name``. For example, the URL patterns in the tutorial are changed from:
|
||||
|
||||
.. code-block:: python
|
||||
:caption: mysite/urls.py
|
||||
:caption: ``mysite/urls.py``
|
||||
|
||||
urlpatterns = [
|
||||
url(r'^polls/', include('polls.urls', namespace="polls")),
|
||||
@ -1274,7 +1274,7 @@ attribute (as below). If the ``app_name`` is set in this new way, the
|
||||
to:
|
||||
|
||||
.. code-block:: python
|
||||
:caption: mysite/urls.py
|
||||
:caption: ``mysite/urls.py``
|
||||
|
||||
urlpatterns = [
|
||||
url(r'^polls/', include('polls.urls')), # 'namespace="polls"' removed
|
||||
@ -1282,7 +1282,7 @@ to:
|
||||
]
|
||||
|
||||
.. code-block:: python
|
||||
:caption: polls/urls.py
|
||||
:caption: ``polls/urls.py``
|
||||
|
||||
app_name = 'polls' # added
|
||||
urlpatterns = [...]
|
||||
@ -1292,7 +1292,7 @@ is deprecated. Instead, pass ``admin.site.urls`` directly to
|
||||
``django.conf.urls.url()``:
|
||||
|
||||
.. code-block:: python
|
||||
:caption: urls.py
|
||||
:caption: ``urls.py``
|
||||
|
||||
from django.conf.urls import url
|
||||
from django.contrib import admin
|
||||
|
@ -343,7 +343,7 @@ modify the pattern to work with any algorithm or with a custom user model.
|
||||
First, we'll add the custom hasher:
|
||||
|
||||
.. code-block:: python
|
||||
:caption: accounts/hashers.py
|
||||
:caption: ``accounts/hashers.py``
|
||||
|
||||
from django.contrib.auth.hashers import (
|
||||
PBKDF2PasswordHasher, SHA1PasswordHasher,
|
||||
@ -363,7 +363,7 @@ First, we'll add the custom hasher:
|
||||
The data migration might look something like:
|
||||
|
||||
.. code-block:: python
|
||||
:caption: accounts/migrations/0002_migrate_sha1_passwords.py
|
||||
:caption: ``accounts/migrations/0002_migrate_sha1_passwords.py``
|
||||
|
||||
from django.db import migrations
|
||||
|
||||
@ -398,7 +398,7 @@ several thousand users, depending on the speed of your hardware.
|
||||
Finally, we'll add a :setting:`PASSWORD_HASHERS` setting:
|
||||
|
||||
.. code-block:: python
|
||||
:caption: mysite/settings.py
|
||||
:caption: ``mysite/settings.py``
|
||||
|
||||
PASSWORD_HASHERS = [
|
||||
'django.contrib.auth.hashers.PBKDF2PasswordHasher',
|
||||
|
@ -19,7 +19,7 @@ Basic forms
|
||||
Given a contact form:
|
||||
|
||||
.. code-block:: python
|
||||
:caption: forms.py
|
||||
:caption: ``forms.py``
|
||||
|
||||
from django import forms
|
||||
|
||||
@ -34,7 +34,7 @@ Given a contact form:
|
||||
The view can be constructed using a ``FormView``:
|
||||
|
||||
.. code-block:: python
|
||||
:caption: views.py
|
||||
:caption: ``views.py``
|
||||
|
||||
from myapp.forms import ContactForm
|
||||
from django.views.generic.edit import FormView
|
||||
@ -97,7 +97,7 @@ First we need to add :meth:`~django.db.models.Model.get_absolute_url()` to our
|
||||
``Author`` class:
|
||||
|
||||
.. code-block:: python
|
||||
:caption: models.py
|
||||
:caption: ``models.py``
|
||||
|
||||
from django.db import models
|
||||
from django.urls import reverse
|
||||
@ -113,7 +113,7 @@ work. Notice how we're just configuring the generic class-based views
|
||||
here; we don't have to write any logic ourselves:
|
||||
|
||||
.. code-block:: python
|
||||
:caption: views.py
|
||||
:caption: ``views.py``
|
||||
|
||||
from django.urls import reverse_lazy
|
||||
from django.views.generic.edit import CreateView, DeleteView, UpdateView
|
||||
@ -147,7 +147,7 @@ and :attr:`~django.views.generic.edit.FormMixin.form_class` attributes, an
|
||||
Finally, we hook these new views into the URLconf:
|
||||
|
||||
.. code-block:: python
|
||||
:caption: urls.py
|
||||
:caption: ``urls.py``
|
||||
|
||||
from django.urls import path
|
||||
from myapp.views import AuthorCreateView, AuthorDeleteView, AuthorUpdateView
|
||||
@ -188,7 +188,7 @@ you can use a custom :class:`~django.forms.ModelForm` to do this. First, add
|
||||
the foreign key relation to the model:
|
||||
|
||||
.. code-block:: python
|
||||
:caption: models.py
|
||||
:caption: ``models.py``
|
||||
|
||||
from django.contrib.auth.models import User
|
||||
from django.db import models
|
||||
@ -204,7 +204,7 @@ to edit, and override
|
||||
:meth:`~django.views.generic.edit.ModelFormMixin.form_valid()` to add the user:
|
||||
|
||||
.. code-block:: python
|
||||
:caption: views.py
|
||||
:caption: ``views.py``
|
||||
|
||||
from django.contrib.auth.mixins import LoginRequiredMixin
|
||||
from django.views.generic.edit import CreateView
|
||||
|
@ -221,7 +221,7 @@ We'll demonstrate this with the ``Author`` model we used in the
|
||||
:doc:`generic class-based views introduction<generic-display>`.
|
||||
|
||||
.. code-block:: python
|
||||
:caption: views.py
|
||||
:caption: ``views.py``
|
||||
|
||||
from django.http import HttpResponseForbidden, HttpResponseRedirect
|
||||
from django.urls import reverse
|
||||
@ -253,7 +253,7 @@ look up the author we're interested in, which it does with a call to
|
||||
We can hook this into our URLs easily enough:
|
||||
|
||||
.. code-block:: python
|
||||
:caption: urls.py
|
||||
:caption: ``urls.py``
|
||||
|
||||
from django.urls import path
|
||||
from books.views import RecordInterestView
|
||||
|
@ -1474,7 +1474,7 @@ For example, if you had ``organic.py`` and ``synthetic.py`` in the ``models``
|
||||
directory:
|
||||
|
||||
.. code-block:: python
|
||||
:caption: myapp/models/__init__.py
|
||||
:caption: ``myapp/models/__init__.py``
|
||||
|
||||
from .organic import Person
|
||||
from .synthetic import Robot
|
||||
|
@ -227,7 +227,7 @@ We already know what we want our HTML form to look like. Our starting point for
|
||||
it in Django is this:
|
||||
|
||||
.. code-block:: python
|
||||
:caption: forms.py
|
||||
:caption: ``forms.py``
|
||||
|
||||
from django import forms
|
||||
|
||||
@ -277,7 +277,7 @@ To handle the form we need to instantiate it in the view for the URL where we
|
||||
want it to be published:
|
||||
|
||||
.. code-block:: python
|
||||
:caption: views.py
|
||||
:caption: ``views.py``
|
||||
|
||||
from django.http import HttpResponseRedirect
|
||||
from django.shortcuts import render
|
||||
@ -404,7 +404,7 @@ Consider a more useful form than our minimal example above, which we could use
|
||||
to implement "contact me" functionality on a personal website:
|
||||
|
||||
.. code-block:: python
|
||||
:caption: forms.py
|
||||
:caption: ``forms.py``
|
||||
|
||||
from django import forms
|
||||
|
||||
@ -453,7 +453,7 @@ values to a Python ``int`` and ``float`` respectively.
|
||||
Here's how the form data could be processed in the view that handles this form:
|
||||
|
||||
.. code-block:: python
|
||||
:caption: views.py
|
||||
:caption: ``views.py``
|
||||
|
||||
from django.core.mail import send_mail
|
||||
|
||||
@ -526,7 +526,7 @@ In your templates:
|
||||
Then you can configure the :setting:`FORM_RENDERER` setting:
|
||||
|
||||
.. code-block:: python
|
||||
:caption: settings.py
|
||||
:caption: ``settings.py``
|
||||
|
||||
from django.forms.renderers import TemplatesSetting
|
||||
|
||||
|
@ -22,7 +22,7 @@ Basic file uploads
|
||||
Consider a form containing a :class:`~django.forms.FileField`:
|
||||
|
||||
.. code-block:: python
|
||||
:caption: forms.py
|
||||
:caption: ``forms.py``
|
||||
|
||||
from django import forms
|
||||
|
||||
@ -46,7 +46,7 @@ Most of the time, you'll pass the file data from ``request`` into the form as
|
||||
described in :ref:`binding-uploaded-files`. This would look something like:
|
||||
|
||||
.. code-block:: python
|
||||
:caption: views.py
|
||||
:caption: ``views.py``
|
||||
|
||||
from django.http import HttpResponseRedirect
|
||||
from django.shortcuts import render
|
||||
@ -146,7 +146,7 @@ If you want to upload multiple files using one form field, set the ``multiple``
|
||||
HTML attribute of field's widget:
|
||||
|
||||
.. code-block:: python
|
||||
:caption: forms.py
|
||||
:caption: ``forms.py``
|
||||
|
||||
from django import forms
|
||||
|
||||
@ -158,7 +158,7 @@ Then override the ``post`` method of your
|
||||
uploads:
|
||||
|
||||
.. code-block:: python
|
||||
:caption: views.py
|
||||
:caption: ``views.py``
|
||||
|
||||
from django.views.generic.edit import FormView
|
||||
from .forms import FileFieldForm
|
||||
|
@ -767,7 +767,7 @@ so that it takes the instance namespace into consideration when creating and
|
||||
displaying polls.
|
||||
|
||||
.. code-block:: python
|
||||
:caption: urls.py
|
||||
:caption: ``urls.py``
|
||||
|
||||
from django.urls import include, path
|
||||
|
||||
@ -777,7 +777,7 @@ displaying polls.
|
||||
]
|
||||
|
||||
.. code-block:: python
|
||||
:caption: polls/urls.py
|
||||
:caption: ``polls/urls.py``
|
||||
|
||||
from django.urls import path
|
||||
|
||||
@ -836,7 +836,7 @@ module, or a string reference to the module, to :func:`~django.urls.include`,
|
||||
not the list of ``urlpatterns`` itself.
|
||||
|
||||
.. code-block:: python
|
||||
:caption: polls/urls.py
|
||||
:caption: ``polls/urls.py``
|
||||
|
||||
from django.urls import path
|
||||
|
||||
@ -850,7 +850,7 @@ not the list of ``urlpatterns`` itself.
|
||||
]
|
||||
|
||||
.. code-block:: python
|
||||
:caption: urls.py
|
||||
:caption: ``urls.py``
|
||||
|
||||
from django.urls import include, path
|
||||
|
||||
|
@ -207,7 +207,7 @@ To begin, here's a small configuration that will allow you to output all log
|
||||
messages to the console:
|
||||
|
||||
.. code-block:: python
|
||||
:caption: settings.py
|
||||
:caption: ``settings.py``
|
||||
|
||||
import os
|
||||
|
||||
@ -235,7 +235,7 @@ logging system print more messages from just the :ref:`django-logger` named
|
||||
logger:
|
||||
|
||||
.. code-block:: python
|
||||
:caption: settings.py
|
||||
:caption: ``settings.py``
|
||||
|
||||
import os
|
||||
|
||||
@ -272,7 +272,7 @@ You don't have to log to the console. Here's a configuration which writes all
|
||||
logging from the :ref:`django-logger` named logger to a local file:
|
||||
|
||||
.. code-block:: python
|
||||
:caption: settings.py
|
||||
:caption: ``settings.py``
|
||||
|
||||
LOGGING = {
|
||||
'version': 1,
|
||||
@ -299,7 +299,7 @@ location that's writable by the user that's running the Django application.
|
||||
Finally, here's an example of a fairly complex logging setup:
|
||||
|
||||
.. code-block:: python
|
||||
:caption: settings.py
|
||||
:caption: ``settings.py``
|
||||
|
||||
LOGGING = {
|
||||
'version': 1,
|
||||
@ -444,7 +444,7 @@ Here's an example that disables Django's logging configuration and then
|
||||
manually configures logging:
|
||||
|
||||
.. code-block:: python
|
||||
:caption: settings.py
|
||||
:caption: ``settings.py``
|
||||
|
||||
LOGGING_CONFIG = None
|
||||
|
||||
|
@ -88,7 +88,7 @@ must ensure that they are configured correctly, by calling
|
||||
For example, assuming the following class-based view:
|
||||
|
||||
.. code-block:: python
|
||||
:caption: views.py
|
||||
:caption: ``views.py``
|
||||
|
||||
from django.views.generic import TemplateView
|
||||
|
||||
@ -105,7 +105,7 @@ the view, then passing a ``request`` to ``setup()``, before proceeding with
|
||||
your test's code:
|
||||
|
||||
.. code-block:: python
|
||||
:caption: tests.py
|
||||
:caption: ``tests.py``
|
||||
|
||||
from django.test import RequestFactory, TestCase
|
||||
from .views import HomeView
|
||||
@ -412,7 +412,7 @@ following structure::
|
||||
Let's take a look inside a couple of those files:
|
||||
|
||||
.. code-block:: python
|
||||
:caption: runtests.py
|
||||
:caption: ``runtests.py``
|
||||
|
||||
#!/usr/bin/env python
|
||||
import os
|
||||
@ -440,7 +440,7 @@ command-line options for controlling verbosity, passing in specific test
|
||||
labels to run, etc.
|
||||
|
||||
.. code-block:: python
|
||||
:caption: tests/test_settings.py
|
||||
:caption: ``tests/test_settings.py``
|
||||
|
||||
SECRET_KEY = 'fake-key'
|
||||
INSTALLED_APPS = [
|
||||
|
Loading…
Reference in New Issue
Block a user