Installation and use of Python Django (1)

 

Install Django

  1. Query whether django is installed on the machine
  • Click the start button -- run -- enter 'cmd' -- enter the command 'pip show django'
  • pip show django
  • If the following appears, it means that django is installed

  •  Microsoft Windows [版本 6.1.7601]
    版权所有 (c) 2009 Microsoft Corporation。保留所有权利。
    
    C:\Users\Administrator>pip show django
    Name: Django
    Version: 2.0.2
    Summary: A high-level Python Web framework that encourages rapid development and
     clean, pragmatic design.
    Home-page: https://www.djangoproject.com/
    Author: Django Software Foundation
    Author-email: [email protected]
    License: BSD
    Location: c:\users\administrator\appdata\local\programs\python\python36-32\lib\s
    ite-packages
    Requires: pytz
    
    C:\Users\Administrator>
  • If it is not installed, execute the following command
  • pip install django

Introduction to Django

  • Django is an open source web application framework written in Python
  • Django is an ORM framework (Object Relational Mapping)
  • Django uses the MVC design pattern

 

 

  1. MVC Baidu Encyclopedia : The full name is Model View Controller, which is the abbreviation of model-view-controller, a software design paradigm that organizes code with a method of separating business logic, data, and interface display. , which aggregates business logic into one component, and does not need to rewrite business logic while improving and customizing the interface and user interaction.
  2. Popular explanation : a form of organization and management of documents! Don't be intimidated by the abbreviation, it's actually a way to put different types of files in different directories, and then take a fancy name. Of course, there are many benefits it brings, such as front-end and back-end separation, loose coupling, etc., which will not be described in detail.       
  3. Model (model): Define database-related content, generally placed in the models.py file.

    View (view): Define HTML and other static web page files, that is, those front-end things such as html, css, and js.

    Controller (controller): Define business logic related, which is your main code.

Create a Django project

  • Open the PyCharm editor--File in the upper left corner--click New Project--select Django

  • Django will automatically generate the following directory structure:

  • The directory with the same name as the project is the configuration file, and the templates directory is where the html file is stored, which is the T in MTV.
  • manage.py is the django project management file.

Next we enter the dj_MySchool directory and start the server:

View and URL configuration

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325170949&siteId=291194637