Django Is an open source Web Application framework , Yes Python It's written in . It was originally developed to manage some of the Lawrence group's Focus on news content Web site . -- Baidu Encyclopedia
Use Django Most web sites are used for content management systems , Compared with Flask( the other one PythonWeb frame ), He is a heavy frame , Can do almost anything .
Learn how to create django Before project construction , We need to understand the virtual environment first (virtual environment) This thing
Popular speaking , When developing multiple projects , Each project has its own modules , We can't put them all in one place , For example, I used in this project django The version is 2.2, And the version used in the other project does 3.1, That would create chaos , It is not convenient for the packaging and release of products . Virtual environment can be understood as a small square in a large wardrobe , You put down your clothes for tomorrow in this square , Put down your daily allowance in another box .
First of all, make sure that our computer is installed with Python Of , And the system environment variables of the computer ( My computer — Right click , attribute — Advanced system setup — environment variable ) Configured Python The path of
If there is , It proves that we have the ability to install python Virtual environment conditions ! It shows that it has been successful 1/4.
Next , Prepare a folder , Used to store our Django Engineering documents , Create a new folder in this folder , Name yourself .
Open the system terminal
For example, I store my system D disc :
Input d: After entering D disc , Then input cd Python/Django/one The yellow font is the location of my project folder
What we need to do next is to create a virtual environment under this path , In the future, when we create another project, we can create a virtual environment in the new folder
Installing a virtual environment
Enter... In the current path pip3 install virtualenv( If the computer has only python3, be 3 No , Direct input pip install virtualenv)
When the loading is completed, the download is successful !
Next, enter... Under the path :
two Environment name , Unfixed , Just remember , Something will jump out , It indicates that the creation is successful
Then the name of your newly created virtual environment will appear in front of the original path
To exit the virtual environment, enter :deactivate
that will do
Enter again workon two
that will do
This completes the download and creation of our virtual environment
pip install django==3.2
, If the speed is too slow , Just press the Ctrl+C Finish the process first , Input again pip install django==3.2 -i https://pypi.tuna.tsinghua.edu.cn/simple
.django-admin startproject ( Project name )
one
, Why? ?python manage.py startapp App
( I want to create a new one next time App You can also use this statement )python manage.py runserver
You can see the following python manage.py runserver 9000
Successfully created django project , We might think , Where do I write my code ?
Of course not at the terminal , It's too hard . We use it pycharm,pycharm The powerful prompt function can bring great convenience to our development .
You can download it from the official website , Community Edition is fine , But it's best to have a professional version , In this way, the above steps of more than 3000 words can be directly omitted , It's just pycharm The activation of the professional version is a little troublesome , Many students may have wanted to give up when they activated ! Because it is more metaphysical , And the community version can solve the problem , So I won't go into details here .
Let's talk about the method of creating project engineering in professional edition
First of all :
second :
Third :
Finally, click create That is, the creation is successful !