1
0
mirror of https://github.com/django/django.git synced 2025-10-24 06:06:09 +00:00

[4.2.x] Refs #34140 -- Applied rst code-block to non-Python examples.

Thanks to J.V. Zammit, Paolo Melchiorre, and Mariusz Felisiak for
reviews.

Backport of 534ac48297 from main.
This commit is contained in:
Carlton Gibson
2023-02-09 16:48:46 +01:00
committed by Mariusz Felisiak
parent 4a89aa25c9
commit b784768eef
120 changed files with 3998 additions and 1397 deletions

View File

@@ -357,7 +357,9 @@ that's really what happens. ``cd`` to the Django ``tests/`` directory and run:
$ ./runtests.py shortcuts
If the tests ran correctly, you should see one failure corresponding to the test
method we added, with this error::
method we added, with this error:
.. code-block:: pytb
ImportError: cannot import name 'make_toast' from 'django.shortcuts'
@@ -407,7 +409,9 @@ Writing Documentation
This is a new feature, so it should be documented. Open the file
``docs/topics/http/shortcuts.txt`` and add the following at the end of the
file::
file:
.. code-block:: rst
``make_toast()``
================
@@ -421,7 +425,9 @@ file::
Since this new feature will be in an upcoming release it is also added to the
release notes for the next version of Django. Open the release notes for the
latest version in ``docs/releases/``, which at time of writing is ``2.2.txt``.
Add a note under the "Minor Features" header::
Add a note under the "Minor Features" header:
.. code-block:: rst
:mod:`django.shortcuts`
~~~~~~~~~~~~~~~~~~~~~~~

View File

@@ -20,7 +20,9 @@ Get the latest version of Python at https://www.python.org/downloads/ or with
your operating system's package manager.
You can verify that Python is installed by typing ``python`` from your shell;
you should see something like::
you should see something like:
.. code-block:: pycon
Python 3.x.y
[GCC 4.x] on linux

View File

@@ -66,7 +66,9 @@ Enjoy the free API
With that, you've got a free, and rich, :doc:`Python API </topics/db/queries>`
to access your data. The API is created on the fly, no code generation
necessary::
necessary:
.. code-block:: pycon
# Import the models we created from our "news" app
>>> from news.models import Article, Reporter

View File

@@ -53,7 +53,9 @@ projects and ready to publish for others to install and use.
Your project and your reusable app
==================================
After the previous tutorials, our project should look like this::
After the previous tutorials, our project should look like this:
.. code-block:: text
mysite/
manage.py
@@ -256,9 +258,11 @@ this. For a small app like polls, this process isn't too difficult.
#. It's optional, but recommended, to include detailed documentation with your
app. Create an empty directory ``django-polls/docs`` for future
documentation. Add an additional line to ``django-polls/MANIFEST.in``::
documentation. Add an additional line to ``django-polls/MANIFEST.in``:
recursive-include docs *
.. code-block:: text
recursive-include docs *
Note that the ``docs`` directory won't be included in your package unless
you add some files to it. Many Django apps also provide their documentation
@@ -291,16 +295,20 @@ working. We'll now fix this by installing our new ``django-polls`` package.
solution (see below).
#. To install the package, use pip (you already :ref:`installed it
<installing-reusable-apps-prerequisites>`, right?)::
<installing-reusable-apps-prerequisites>`, right?):
python -m pip install --user django-polls/dist/django-polls-0.1.tar.gz
.. code-block:: shell
python -m pip install --user django-polls/dist/django-polls-0.1.tar.gz
#. With luck, your Django project should now work correctly again. Run the
server again to confirm this.
#. To uninstall the package, use pip::
#. To uninstall the package, use pip:
python -m pip uninstall django-polls
.. code-block:: shell
python -m pip uninstall django-polls
Publishing your app
===================

View File

@@ -76,7 +76,9 @@ work, see :ref:`troubleshooting-django-admin`.
Put your code in some directory **outside** of the document root, such as
:file:`/home/mycode`.
Let's look at what :djadmin:`startproject` created::
Let's look at what :djadmin:`startproject` created:
.. code-block:: text
mysite/
manage.py
@@ -224,7 +226,9 @@ and type this command:
$ python manage.py startapp polls
That'll create a directory :file:`polls`, which is laid out like this::
That'll create a directory :file:`polls`, which is laid out like this:
.. code-block:: text
polls/
__init__.py
@@ -257,7 +261,9 @@ This is the simplest view possible in Django. To call the view, we need to map
it to a URL - and for this we need a URLconf.
To create a URLconf in the polls directory, create a file called ``urls.py``.
Your app directory should now look like::
Your app directory should now look like:
.. code-block:: text
polls/
__init__.py

View File

@@ -381,7 +381,9 @@ We're using this instead of simply typing "python", because :file:`manage.py`
sets the :envvar:`DJANGO_SETTINGS_MODULE` environment variable, which gives
Django the Python import path to your :file:`mysite/settings.py` file.
Once you're in the shell, explore the :doc:`database API </topics/db/queries>`::
Once you're in the shell, explore the :doc:`database API </topics/db/queries>`:
.. code-block:: pycon
>>> from polls.models import Choice, Question # Import the model classes we just wrote.
@@ -468,7 +470,9 @@ you aren't familiar with time zone handling in Python, you can learn more in
the :doc:`time zone support docs </topics/i18n/timezones>`.
Save these changes and start a new Python interactive shell by running
``python manage.py shell`` again::
``python manage.py shell`` again:
.. code-block:: pycon
>>> from polls.models import Choice, Question

View File

@@ -206,7 +206,9 @@ In the terminal, we can run our test:
$ python manage.py test polls
and you'll see something like::
and you'll see something like:
.. code-block:: shell
Creating test database for alias 'default'...
System check identified no issues (0 silenced).
@@ -267,7 +269,9 @@ past:
now = timezone.now()
return now - datetime.timedelta(days=1) <= self.pub_date <= now
and run the test again::
and run the test again:
.. code-block:: pytb
Creating test database for alias 'default'...
System check identified no issues (0 silenced).
@@ -376,13 +380,17 @@ it earlier, check it before continuing.
Next we need to import the test client class (later in ``tests.py`` we will use
the :class:`django.test.TestCase` class, which comes with its own client, so
this won't be required)::
this won't be required):
.. code-block:: pycon
>>> from django.test import Client
>>> # create an instance of the client for our use
>>> client = Client()
With that ready, we can ask the client to do some work for us::
With that ready, we can ask the client to do some work for us:
.. code-block:: pycon
>>> # get a response from '/'
>>> response = client.get('/')