In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article will explain in detail what Django is in python. The editor thinks it is very practical, so I share it with you as a reference. I hope you can get something after reading this article.
1. Introduction to Django what is Django?
Django is a free and open source Web framework developed with Python, which can be used to quickly build high-performance, elegant websites! The frame pattern of MVC- > MVT is adopted.
Django prospect
In Python, there are 13045 packages related to web development, of which django accounts for 9091, or about 70%. At the same time, there are as many as 54 active web frameworks in Python, of which Django,flask is the most active. Django is one of the best. So far, more than 5200 medium and large websites have been developed using Django. The more well-known companies that use Django:
Domestic: Douban, Zhihu, etc.
Abroad: Google, YouTube (oil pipe), Instagram (photo wall)-> facebook, etc.
Django framework core
1. An object-oriented mapper that acts as a medium between the data model (defined in the form of a Python class) and a relational database
2. A URL dispenser based on regular expression (routing dispenser)
3. A view system for processing requests
4. A template system (HTML, css, js).
two。 Design pattern MVT pattern
The MVT design pattern of Django consists of three parts: Model (model), View (view) and Template (template), corresponding to models.py, views.py and templates folders in a single app directory. They seem to be inconsistent with the MVC design pattern, but they are essentially the same. The correspondence between Django's MVT design pattern and the classic MVC is as follows.
Django Model (model): similar to the model Model in MVC
Django View (view): similar to the controller Controller in MVC, it is responsible for reading data from the database according to the user's request, specifying the way to display the data to the y user (web page or json data), and can also deal with the data submitted by the user.
Django Template (template): similar to the view View in MVC, it is used to render the data passed by Django View and also determines the appearance of the user interface. Forms are also included to collect the data passed by the user.
The most important thing in the Django MVT design pattern is the view, and the view interacts with both the model and the templates. When a user sends a request (request), the Django parses the request header information, parses the url address that the user needs to access, and then forwards the request to the corresponding view for processing according to the corresponding relationship defined in the routing urls.py. The view reads the required data from the database, specifies the rendering template, and finally returns the response data.
3. Brief introduction of development environment
1. System support: linux (recommended, commonly used in projects), mac,windows
Unix
It is recommended that linux:linux is more compatible than mac and windows.
2.linux system
Install the linux system in the virtual machine (recommended)
Use CVM
Install dual system
3. Development environment support
Python
Pip
Virtualenv (virtual environment)
Mysql
Note: why do you need to develop in a virtual environment:
4. Clean, environment and environment are independent of each other. Eg: the crawler project is placed in environment 1 django in environment 2, so the use of packages in the two projects will not conflict with each other.
4. Create a virtual environment 4.1. First install the package for the management environment and the virtual environment package 4.1.1 install the environment management package virtualenvwrapper
Note: the editor terminal of pycharm is the same as the cmd terminal, so the installation operation is the same in pycharm
4.1.2 install the virtual environment package virtualenv
4.1.3 check the pip list to see if the installation is successful
Check the existence of the above two packages, so the installation is successful.
4.2 Operation on the virtual environment 4.2.1 create a virtual environment
Create virtual environment command to create an environment name for mkvirtualenv
(django2108_1) indicates that it has entered the environment.
4.2.2 View the packages in the virtual environment and install the Django package
4.2.3 exit the virtual environment
The command is deactivate
4.2.4 View creation of all virtual environments
The command is workon
4.2.5 enter the specified virtual environment
The command is: virtual environment created by workon
4.2.6 Delete virtual environment
The command is: rmvirtualenv virtual environment name
Note: to delete a virtual environment, you must first exit the virtual environment you want to delete.
4.3 change the path in the virtual environment (the path to create the virtual environment is on disk c by default)
According to your choice, the environment variables are stored in different paths by creating the system variable WORKON_HOME.
5. Project creation and service startup 5.1 create project 5.1.1 create a virtual environment again
5.1.2 create a folder on disk to hold the project
5.1.3 Open the folder where the project is stored as the project file
5.1.4 add environment variables
5.1.5 install the django package in the new environment
5.1.6 create a project
The command is: django-admin startproject project name
5.1.7 create sub-application
First, cd to the created project path, and then enter the name of the python manage.py startapp sub-application to create the sub-application.
5.1.8 registering sub-applications
5.2 start the service
Method 1: enter the command python manage.py runserver directly in the terminal
Method 2: set the terminal execution parameters in Python
Method 3: by setting Django server (recommended), note: root directory and configuration file need to be set
5.3. Open the web page and view the results
This is the end of this article on "what is Django in python?". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, please share it for more people to see.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.