January 9, 2021 ← Last time: Preparing to connect to Day 3 database
This article is not a single article. I wrote it as a diary, so I think it will be useful for those who are new to it. If you want to learn Django, we recommend reading it from [Day 1] Django Development Environment.
This time I continued to prepare the database for about an hour, but I couldn't do it, so I decided to do it with SQLite, which is included in Django by default. So this time I will move on to the next.
Since the database is SQLite, I would like to move on to application generation. This time I added an application named'base' to create a bulletin board app. This base application is said to be an application that makes the basic configuration functions such as the top page, terms of use, and privacy as the basis of the WEB application.
$ source venv/bin/activate
(venv)$ cd mysite
(venv)$ ./manage.py startapp base
You have now created a thread application.
The generated application is used by embedding it in the project. Add to setting.py.
setting.py
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
+ 'base',
]
New file urls.py in the generated base directory Let's generate.
base/urls.py
from django.urls import path
name = 'base'
urlpatterns = []
On the other hand, add it to urls.py which is not in the mysite directory.
mysite/urls.py
- from django.urls import path
+ from django.urls import path, include
+ import base
urlpatterns = [
path('admin/', admin.site.urls),
+ path('', include('base.urls'))
]
Here, it seems that it means that the part directly under the domain is directly connected to urls.py of the base application. I don't know what it means.
Up to here for this time
← Last time: Preparing to connect to Day 3 database → Next time: Day 5 View and Template Basics
Recommended Posts