mirror of
https://github.com/django/django.git
synced 2024-12-22 09:05:43 +00:00
Fixed 35506 -- Clarified initial references to URLconf in tutorial 1.
This commit is contained in:
parent
f302343380
commit
2c931fda5b
@ -222,10 +222,25 @@ and put the following Python code in it:
|
|||||||
def index(request):
|
def index(request):
|
||||||
return HttpResponse("Hello, world. You're at the polls index.")
|
return HttpResponse("Hello, world. You're at the polls index.")
|
||||||
|
|
||||||
This is the simplest view possible in Django. To call the view, we need to map
|
This is the most basic view possible in Django. To access it in a browser, we
|
||||||
it to a URL - and for this we need a URLconf.
|
need to map it to a URL - and for this we need to define a URL configuration,
|
||||||
|
or "URLconf" for short. These URL configurations are defined inside each
|
||||||
|
Django app, and they are Python files named ``urls.py``.
|
||||||
|
|
||||||
|
To define a URLconf for the ``polls`` app, create a file ``polls/urls.py``
|
||||||
|
with the following content:
|
||||||
|
|
||||||
|
.. code-block:: python
|
||||||
|
:caption: ``polls/urls.py``
|
||||||
|
|
||||||
|
from django.urls import path
|
||||||
|
|
||||||
|
from . import views
|
||||||
|
|
||||||
|
urlpatterns = [
|
||||||
|
path("", views.index, name="index"),
|
||||||
|
]
|
||||||
|
|
||||||
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
|
.. code-block:: text
|
||||||
@ -241,21 +256,9 @@ Your app directory should now look like:
|
|||||||
urls.py
|
urls.py
|
||||||
views.py
|
views.py
|
||||||
|
|
||||||
In the ``polls/urls.py`` file include the following code:
|
The next step is to configure the global URLconf in the ``mysite`` project to
|
||||||
|
include the URLconf defined in ``polls.urls``. To do this, add an import for
|
||||||
.. code-block:: python
|
``django.urls.include`` in ``mysite/urls.py`` and insert an
|
||||||
:caption: ``polls/urls.py``
|
|
||||||
|
|
||||||
from django.urls import path
|
|
||||||
|
|
||||||
from . import views
|
|
||||||
|
|
||||||
urlpatterns = [
|
|
||||||
path("", views.index, name="index"),
|
|
||||||
]
|
|
||||||
|
|
||||||
The next step is to point the root URLconf at the ``polls.urls`` module. In
|
|
||||||
``mysite/urls.py``, add an import for ``django.urls.include`` and insert an
|
|
||||||
:func:`~django.urls.include` in the ``urlpatterns`` list, so you have:
|
:func:`~django.urls.include` in the ``urlpatterns`` list, so you have:
|
||||||
|
|
||||||
.. code-block:: python
|
.. code-block:: python
|
||||||
|
Loading…
Reference in New Issue
Block a user