django[Basic Knowledge]

Source: Internet
Author: User

Python's most functional web framework: Django, the framework itself integrates ORM, model binding, template engine, caching, session, and many more.

The following actions are required to use Django:

1. There are two ways to create a Django project.

A, command operation:

Django-admin startproject dg_web//dg_web for project name

B. Create a new Django project directly under the IDE of the development environment

The file directory after the project was created is as follows:

2, the creation of the project under the establishment of a functional program, the operation is as follows:

Command line: Python manage.py startapp app01//Create function program APP01, create multiple then replace APP01 with new program

3, initialize the database, Django itself admin uses the data for Sqlite3, initialize the database command steps are as follows:

A, Python manage.py makemigrations//Generate config file

B, Python manage.py migrate//Generate database-related content based on configuration files

4, if APP01 need to create their own database tables, you need to first create a table in the models file class, and then perform the 3rd step operation.

A, example: Models file to add a user information class:

 from Import Models # Create your models here. class UserInfo (models. Model):    = models. Charfield (max_length=16)     #建立username字段        = models. Charfield (max_length=16)     #建立password字段     = models. Integerfield ()                    #建立age字段

b, in the Global configuration file Settings add App01 as the location:

C, the implementation of the 3rd step:

I, Python manage.py makemigrations//Generate config file, create 0001_initial.py file

II, Python manage.py migrate//based on the configuration file to generate database-related content, you can use the tool connection Sqlite3 view the new UserInfo table information,

django[Basic Knowledge]

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.