Django command, MTV model and configuration, django command mtv Model
1. MTV Model
Django's MTV representatives:
Model: The business object and database object (ORM)
Template: displays pages to users.
View: responsible for business logic and calling Model and Template when appropriate
In addition, Django also has a urls distributor which distributes URL-specific page requests to different views and calls the corresponding Model and Template.
2. Django basic command 2.1 Download Django
pip3 install django
2.2 create a Django project
Django-admin.py startproject [preject name]
Generated directory structure:
- Manage. py ----- A tool in the Django project that can call django shell and database.
- Settings. py ---- contains the default settings of the project, including database information, debugging flag, and other working variables.
- Urls. py ----- maps the URL mode to the application.
2.3 create a Django app
python manage.py startapp blog
2.4 start Django
python manage.py runserver 8080
2.5 database commands
# Create or modify a table. When a class is added or modified in models. py, You can automatically create and modify the python manage. py makemigrationspython manage. py migrate table in the database.
# This command will ask whether it is yes or no. Selecting yes will clear all the data, leaving only the empty table python manage. py flush
Database-related. For details, see the Django model.
2.6 create a super Administrator
'''Python manage. py createsuperuser # enter the user name and password as prompted. Leave the mailbox blank. the user name and password are required. # You can use python manage to modify the user password. py changepassword username '''
2.7 Django project environment Terminal
# You can call the API in models. py of the current project in this shell. It is very convenient to test the operation data in python manage. py shell.
'''Django automatically enters the database set in settings. py. If it is MySQL or postgreSQL, you are required to enter the Database User Password to execute the database SQL statement on this terminal. If you are familiar with SQL, you may like this method '''python manage. py dbshell
2.8 view more commands
# View all the commands python manage. py
3. static file configuration in the Development Environment
3.1 static Configuration