Django introduction installation and creation


Django installation

Command line installation

pip install django==1.11.9

Pycharm installation


Django basic operation

Command line operation

#1. Create Django project
#Website is a user-defined item name, which can be changed
django-admin startproject website

#2. Launch Django project
#Switch the path to the project path before starting the project
cd D:/website
python runserver

#3. Create an application
#Application01 is a custom application name, which can be changed
python startapp application01


Pycharm operation

  1. Create Django project: new project select Django to create Django project (only supported by pycharm Professional Edition)


  1. Launch Django project
    • Method 1: start from the command line
    • Method 2: click the green arrow in the upper right corner of pycharm to start


  1. Create application
    • Method 1: directly create a project through pycharm. Only one project can be created
    • Method 2: create from the command line
    • Method 3: create a task through Task

Introduction to main documents of Django

  • Website site project folder
    • Web site folder with the same name
    • Django entry file
    • Db.sqlite3 Django’s own database
    • Application01 application folder
      • Django background management
      • registered for use
      • Migrations folder database migration records
      • database related model class (ORM)
      • test file
      • view layer

Difference between command line and pycharm

  1. When pycharm creates a project, it automatically creates a Templates folder, which needs to be created manually on the command line
  2. When pycharm creates an application, it will automatically configure the application path in the configuration file, and the command line needs to be added manually
#To create an application, you must configure the application path in the configuration file

    #Configuration mode 1: complete form
    #Configuration mode 2: short form
    # 'application1',

Introduction to setting configuration file

  • BASE_DIRCurrent project path
  • DEBUGCode debugging. After the project goes online, the result needs to be changed toFalse
  • ALLOWED_HOSTSHosts allowed to access
  • INSTALLED_APPSFor registered applications, Django comes with six function modules by default
  • MIDDLEWAREDjango Middleware
  • TEMPLATESHTML file storage path configuration
  • DATABASESDatabase specified by the project

Current environment:
Python version: Python 3.6.8
Django version: Django 1.11.9