[Day 4] Application creation

January 9, 2021 ← Last time: Preparing to connect to Day 3 database

Precautionary statement

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.

Introduction

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.

Application generation

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.

Embed the 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',
 ]

Application URL settings

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

[Day 4] Application creation
Web application creation with Django
"Trash classification by image!" App creation diary day3 ~ Web application with Django ~
File creation
Python day 1
Web application development in Go language_Hands-on day 1
WEB application development using Django [Admin screen creation]
Until Django application creation by terminal (development environment)