Django learning---Day1-concept and environment configuration

  • Django concepts
  • Framework introduction
  • main idea
  • MVC Design Pattern
  • MTV Design Patterns
  • Creation of Virtualenv virtual environment
  • Configuration of the pymysql environment
  • Django package installation

Django concepts

Django is an open source web application framework written in Python. The frame pattern of MTV is adopted, namely model M, template T and view V. It was originally developed to manage some news content-based websites under the Lawrence Publishing Group, that is, CMS (Content Management System) software. and released under the BSD license in July 2005. The framework is named after Belgian gypsy jazz guitarist Django Reinhardt.

Framework introduction

The Django project is a Python customization framework that originated from an online news Web site and was released as open source in 2005. The core components of the Django framework are:

  • Object Relational Mapping for Model Creation
  • Perfect management interface designed for end users
  • Top-notch URL design
  • Designer friendly templating language
  • cache system

main idea

  • Decoupling decouples the association between each module, so that each module is independent of each other, and can be maintained separately during maintenance

MVC Design Pattern

  • Programming mode
    model - model - data storage layer is used to encapsulate data related to the business logic of the application, as well as the processing of heap data, that is, the model object is responsible for accessing data in the database
    view - view - presentation layer is responsible for data display and Rendering, which is created based on model data, renders html pages to users, or returns data to the user
    controller — the controller business logic layer is the part of the application that handles user interaction.

MTV Design Patterns

Django's MTV mode is essentially the same as MVC. It is also to maintain a loosely coupled relationship between components, but the definition is slightly different. Django's MTV is the value:
M stands for Model: responsible for the relationship between business objects and databases Mapping (ORM).
T stands for Template: responsible for how to display the page to the user (html).
V stands for View: Responsible for business logic and calling Model and Template when appropriate.

Creation of Virtualenv virtual environment

Each project needs to have its own operating environment. A project is often developed by a team. At the same time, the libraries installed by each project are very different. Therefore, using a virtual environment will separate different project environments.
Installation steps: (python 3.6.5 is used here)
1. First create a new folder - env-all
2.cmd enter the folder
3. Install the virtual environment
pip install virtualenv
4. In the folder env-all directory, specify the way to install the python version in the virtual environment
virtualenv –no-site-packages -p "The installation path of the python interpreter in your computer\python. exe” to create the file name of the virtual environment
virtualenv –no-site-packages -p “C:\Program Files\Python36\python.exe” envtest
5. Enter the virtual environment cd and enter the Scripts file cd
under the created virtual environment folder
C:\env-all\envtest
6. Activate the virtual environment (only after activating the virtual environment, you can proceed to the next step)
cd C:\Scripts
Activation command: activate (command under Linux: suorce bin/activate)
Exit command: deactivate

Configuration of the pymysql environment

In the virtualenv virtual environment created in the previous step, continue in the Scripts directory to install the pymysql environment
pip install pymysql

Django package installation

1. Create the python environment in the virtualenv virtual environment, and perform pip install django==1.11.4 in the Scripts directory in the virtualenv environment
2. Check whether django is successfully installed Enter python
in cmd to enter the python interactive environment
import django
django. get_version() when '1.11.4'
is displayed in the interactive environment

Guess you like

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