[PYTHON] Organize [Django] commands and roles

Creating a project

command


django-admin startproject {Project name}

Creating an application

The following command in the directory where manage.py is located

command


python manage.py startapp {app name}

Create directory for url

{app name}/urls.py


from django.urls import path

from . import views

urlpatterns = [
    path('', views.index, name='index'),
]

{Project name} /urls.py

Write the URLConf from each application in this urlpatterns

{Project name}/urls.py


from django.contrib import admin
from django.urls import include, path

urlpatterns = [
    path('polls/', include('polls.urls')),
    path('admin/', admin.site.urls),
]

various settings

Time zone and language code

{Project name}/settiong.py


LANGUAGE_CODE = 'ja'

TIME_ZONE = 'Asia/Tokyo'

Creating a database

migrate command ... Creates tables for all required databases according to the database settings in the file

command


python manage.py migrate

Reflect the model

command


python manage.py makemigrations {Application name}

You can run make migrations to tell Django's model that it has changed and save it to reflect the change.

About Django Admin

Django Admin is a page where you can edit website information from your browser that only administrators can enter. You can access the admin site, which only the administrator can enter, by creating an admin user.

command


python  python manage.py createsuperuser

Start the management server

To start the management server, start the server with python manage.py runserver. Then go to the local domain "/ admin /", that is, http://127.0.0.1:8000/admin/. When you access it, the following screen will be displayed and enter the Username and Password created by the admin user. image.png

Allow apps to be edited on admin

To be able to edit the app on admin, edit {app name} /admin.py. For example, to tell admin that the Question object has an admin interface, write:

{app name}/admin.py


from django.contrib import admin

from .models import Question

admin.site.register(Question)

Continued

It's going to be long, so cut it. Continued ⇒ {comming soon}

reference

Recommended Posts

Organize [Django] commands and roles
Django commands ignore USE_I18N
[Django series] Basic commands
Django --models.py and admin.py
[For beginners] Django Frequently used commands and reference collection
Install Python 3.7 and Django 3.0 (CentOS)
Django installation and operation check
Django input check and calendar input
django timezone and language settings
Create and list Django models
Create custom Django commands and run them from the command line
Basic knowledge of Linux and basic commands
[Note] Django project creation and terminology
Differences between yum commands and APT commands
Prevent double launch of django commands
HTTPS with Django and Let's Encrypt
Organize Java and Go pass / reference
Organize machine learning and deep learning platforms
Commands for creating SNS with Django
Note: Linux concepts and minimum commands
Organize the flow when running Django using NGINX and gunicorn (personal memo)