P58 Content Review and Knowledge Sorting
1. Install Django
pip install django
2. Create a Django project
django-admin startproject mysite
can be created with cmd window,
can also be created with Pycharm,
create with Pycharm to delete the DIR templates in the setting
3. Create app and register
python manage.py startapp app01
python manage.py startapp app02
setting.pyINSTALLED_APPS = {...."app01.apps.App01Config",}Find html files in order of App registrationOnly after the App is registered can the table be created in the database
4. Configure the static file path and template path (put it in the app directory)
5. Configure the database related operations:
Third-party module (django3)
pip install mysqlclient
FirstTo create a database (use the command to create, modify the character to utf-8, otherwise an error will be reported)
Write the class of the table in models.py
Generate the table in models.py
python manage.pymakemigration
python manage.py migrate
You can also use Django's default file database sqlite3 (usually used for development, less online)
Pycharm needs to be configured to open this file
6. Set the correspondence between URL and function in url.py
7. Write business logic in views.py view function
8. Write HTML templates in the templates directory (template syntax, inheritance)
9.ModelForm and Form components, adding, deleting, modifying and checking functions
Generate HTML tags, (generate default input box)
Data verification (valid)
Save to database (ModelForm)
Get errorsInformation
10.Cookie and session, save user login information
11. Implement user authentication based on middleware, without writing each view function
12.ORM operation
models.User.objects.filter(id="xx")
models.User.objects.filter(id="xxx").order_by("-id")
13. Paging component
14. Verification code
15.Ajax request
16. For more information, you can use the paging component