DJango Note: From the beginning (simplification and splitting of URLConf)

** Until now, all applications have been set with one URLConf, but in reality it is easier to understand if you set each application. ** ** So, create a new URLConf for the polls app as follows.

polls / urls.py (new)
# polls/urls.py
from django.conf.urls import patterns, include, url

urlpatterns = patterns('polls.views',
    url(r'^$', 'index'),
    url(r'^(?P<poll_id>\d+)/$', 'detail'),
    url(r'^(?P<poll_id>\d+)/results/$', 'results'),
    url(r'^(?P<poll_id>\d+)/vote/$', 'vote')
)

Previously, the first string in patterns was empty, but now polls.views has been added casually. By doing this, you can make it smarter than you used to write polls.views.detail or polls.views.results.

Then, link it to polls in the URLConf of the project body as follows.

mysite/urls.py ######

# mysite/urls.py
from django.conf.urls import patterns, include, url

from django.contrib import admin
admin.autodiscover()

urlpatterns = patterns('',
    url(r'^polls/', include('polls.urls')),
    url(r'^admin/', include(admin.site.urls))
)

This is OK.

Next, we will enter Tutorial 4, the last item

Recommended Posts

DJango Note: From the beginning (simplification and splitting of URLConf)
DJango Note: From the beginning (form processing)
DJango Note: From the beginning (using a generic view)
DJango Note: From the beginning (creating a view from a template)
DJango Memo: From the beginning (preparation)
DJango Memo: From the beginning (model settings)
Learning notes from the beginning of Python 1
Omit BOM from the beginning of the string
Learning notes from the beginning of Python 2
DJango Memo: From the beginning (creating a view)
Finding the beginning of Abenomics from NT magnification 2
Finding the beginning of Abenomics from NT magnification 1
DJango Memo: From the beginning (Error screen settings)
[Note] Beginning of programming
The wall of changing the Django service from Python 2.7 to Python 3
Learn Nim with Python (from the beginning of the year).
Study from the beginning of Python Hour1: Hello World
Mathematical understanding of principal component analysis from the beginning
[Django 2.2] Sort and get the value of the relation destination
Study from the beginning of Python Hour8: Using packages
The story of a Django model field disappearing from a class
DJango Memo: From the beginning (more edits to the management screen)
Beginning of Nico Nico Pedia analysis ~ JSON and touch the provided data ~
Note: Get the first and last items of Python OrderedDict non-destructively
Capture GeneratorExit and detect the end of iteration from the generator side
Flow of getting the result of asynchronous processing using Django and Celery
DJango memo: From the beginning (using the management screen) my addictive point
Create custom Django commands and run them from the command line
Find the distance from latitude and longitude (considering the roundness of the earth).
Carefully derive the interquartile range of the standard normal distribution from the beginning
Find the waypoint from latitude and longitude (considering the roundness of the earth).
The day of docker run (note)
The story of Python and the story of NaN
[Note] Django project creation and terminology
First Python 3 ~ The beginning of repetition ~
Existence from the viewpoint of Python
Get the value from the [Django] Form
The meaning of ".object" in Django
Find the inertial spindle and moment of inertia from the inertial tensor with NumPy
DJango memo: From the beginning (editing the management screen) There is a mystery
Get news from three major mobile companies using Django and the News API
Consider the description of Dockerfile (Django + MySQL②)
I tried the asynchronous server of Django 3.0
[Understanding in 3 minutes] The beginning of Linux
This and that of the inclusion notation.
Understand the benefits of the Django Rest Framework
How to check the version of Django
Shout Hello, Reiwa! At the beginning of Reiwa
Review the concept and terminology of regression
The story of trying deep3d and losing
Django project structure customization (splitting and structuring)
Python Note: The secret role of commas
Get the address from latitude and longitude
Get only the text from the Django form.
Consider the description of docker-compose.yml (Django + MySQL ③)
Udemy "Master the basics of Django and create three apps! The results of doing it"
The advantages and disadvantages of Django that people with one year of experience think
How to count the number of elements in Django and output to a template
Deep Learning from scratch The theory and implementation of deep learning learned with Python Chapter 3
Get the last element of the array by splitting the string in Python and PHP