Django command, MTV model and configuration, django command mtv Model

Source: Internet
Author: User
Tags install django

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

 

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.