Create a basic process for Django. Create a process for Django
Django creation process
1. Create a project: django-admin startproject project name
2. Create an application: python manage. py startapp Application name
3. Activate the project: Modify INSTALLED_APPS in the settings. py file. Add the 'Application name' at the end of the list'
4. Configure the mysql database:
Install the pymysql library before configuration.
1) modify the global _ init _. py file in the project directory. Write the following code:
import pymysqlpymysql.install_as_MySQLdb()
2) Modify DATABASES in the settings. py file. Change it to the following:
DATABASES = {'default': {'Engine ': 'django. db. backends. mysql ', 'name': 'database name', 'user': 'database Username', 'Password': 'database password', 'host': 'localhost ', 'post': '200 '}}
5. Create a model class: create a data table in the models. py file under the application directory.
6. Generate a migration file: python manage. py makemigrations
7. Execute the migration file: python manage. py migrate
8. Configure the site
9. Create a template directory and an application template directory
10. Modify the global urls. py file in the project directory. The modified content is as follows:
Urlpatterns = [path ('admin/', admin. site. urls), path ('application name/', include ('application name. urls')]
11. Create and configure urls. py in the application directory. The content is as follows:
From django. urls import pathfrom. import viewsurlpatterns = [path ('route path', views. Corresponding function),]
12. Configure the Application Template path in the settings. py file.
Change the DIRS content in the TEMPLATES list:'Dirs': [OS. path. join (BASE_DIR,'Templates')]
13. Place the front-end files in the template folder.
14. Write view functions in the views. py file
Django creation process