Python3 Development of Advanced-django Framework pre-learning small project (a simple trainee management system)

Source: Internet
Author: User

" " 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:

    1. is form not from, must have method and action
    2. All form labels that get user input are placed in the form form, and the form label must have a Name property
    3. 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)

    1. Python3 manage.py makemigrations---check the models.py changes to your laptop
    2. Python3 manage.py Migrate---translate the modifications into SQL statements, go to database execution

5. Steps to create a new Django project:

    1. Create a project (APP)
    2. Creating databases and Configuration databases
    3. Configuring templates and Static file correlation
    4. 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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.