" " write a Student management system table structure: class table: -id -grade_name Students table: -id -student_name -grade related foreign key class table Teacher's Table : -id -teacher_name"
Before writing a small project, let's go over a little bit of knowledge:
1, form form to submit data notes:
- is form not from, must have method and action
- All form labels that get user input are placed in the form form, and the form label must have a Name property
- The form form must have a submit button
2. Get and Post methods:
When to use get:
1. When requesting a webpage from the server
2. When search engine searches
When to use post:
1, when using the table one-way server to submit data
3. The app concept in Django
1. Create an App command
Python3 manage.py Startapp App Name
2. Tell Django what your new app is called
settings.py inside, Installed_apps This configuration item inside add your app
4. The use of the ORM inside Django:
1. Tell Django to connect to the database
DATABASES = {'default': {'ENGINE':'Django.db.backends.mysql',#I'm going to write MySQL here, too.'NAME':'write the name of the connected library here','HOST':'127.0.0.1','PORT': 3306,'USER':'Root','PASSWORD':'123',}}
styles for connecting to a database
2. Tell Django how to connect
Django uses the MySQLdb module to connect to the database by default, and Z tells Django to use the Pymysql module to connect to MySQL.
In the __init__.py file in the same directory as the settings.py, specify that the Pymysql module be used instead of the MYSQLDB
Import pymysqlpymysql.install_as_mysqldb ()
code for __init__.py in the same directory as settings.py
3. Define the class in the app/models.py file, and be sure to inherit the models. Model
4. Perform the action to create the table (command-line input)
- Python3 manage.py makemigrations---check the models.py changes to your laptop
- Python3 manage.py Migrate---translate the modifications into SQL statements, go to database execution
5. Steps to create a new Django project:
- Create a project (APP)
- Creating databases and Configuration databases
- Configuring templates and Static file correlation
- Comment out the CSRF line in settings.py
6. Django Template language (rules for string substitution)
1. {{variable}} {{variable.}}
2. For loop
{% for I in xx%}
{{i}}
{% ENDFOR%}
Forloop.counter---count
3. If judgment
{% if condition%}
Things to do when conditions are established
{% Else%}
Conditions are not set up to do the thing
{% ENDIF%}
Specific code or to GitHub to see it! Links: Https://github.com/qianzeliang/student_manage
Python3 Development of Advanced-django Framework pre-learning small project (a simple trainee management system)