When creating a project , First, the project needs to be described in a normative way , Then establish a virtual environment , To create a project .
To use Django, First, we need to establish a virtual working environment . Virtual work environment is a location of the system , You can install packages , And compare it with others Python Package the isolation .
Next, create a new directory , I'm going to call it learning_log, Then switch to this directory at the terminal ,
And create a virtual environment . You can use the following command to create .
E:\Users\Administrator\PycharmProjects\learning_log>python -m venv ll_env
Modules are used here venv Created a new one called ll_env Virtual environment for .
After setting up the virtual environment , You need to activate it to use :
# This is a windows Activation method in the system , Other systems are different
E:\Users\Administrator\PycharmProjects\learning_log>ll_env\Scripts\activate
(ll_env) E:\Users\Administrator\PycharmProjects\learning_log>
You can see that the environment name is enclosed in parentheses . under these circumstances , Packages can be installed in the environment , Or use a package that has already been installed . stay ll_env Packages installed in are available only when the environment is active .
To stop using virtual environments , Executable command ”deactivate”
After creating and activating the virtual environment , Can be installed Django 了 ,Django It is also available only when the virtual environment is active .
# The download file is very small , But slower
# If used for the first time pip, You can refer to relevant materials first to get familiar with the use method , It has been mentioned in previous articles
(ll_env) E:\Users\Administrator\PycharmProjects\learning_log>pip install Django
In a virtual environment that is still active , Create a new project using the following command :
(ll_env) E:\Users\Administrator\PycharmProjects\learning_log>django-admin.py startproject learning_log .
You can then use the command ’dir’ View the directory under this item on the terminal , Or directly at pycharm compiler , View in file .
notes : Never forget , The next period , There will be some problems when deploying the application . If you forget to add , Delete the created files and folders (ll_env) With the exception of , Rerun the previous command .
learning_log The folder contains several important files . among settings.py Appoint Django How to interact with the system and how to manage the project ; file url.py tell Django What web pages should be created to respond to browser requests ; file wsgi.py help Django Provide the files it creates .