Django Django installation and create projects

virtualenv Description : virtualenv is an independent (relatively) development environment gave us as a development environment for us to operate. In this way, we can start on the same computer multiple versions of Django development, but also do not have to worry about confusing versions, and you can clearly see our installed packages, packages.

Installation virtualenv environment : Enter the command linepip install virtualenv

Create a virtual development environment :

First, create a new folder as the project directory
Here Insert Picture Description
holding down the shift key, right-click the file in the folder, select Open Command Window Here
Here Insert Picture Description
the process of creating command python -m venv djangoProject(djangoProject virtual environment name)
If this error appears you can use python -m venv --without pip djangoProject
Here Insert Picture Description
Here Insert Picture Description
such a virtual Python to built environment

Start the virtual environment with Django installation :

Under running a virtual environment in cmd (file folder you created in the previous step) of activate.bat files in the script directory to start the virtual environment
Here Insert Picture Description
such virtual environment will be started
we can also use the command to exit the virtual environment
to run in a virtual environment among cmd deactivate.bat script files in the directory to exit the virtual environment
Here Insert Picture Description
to start a virtual environment, and then install Django framework in a virtual environment which
enter the command line in a virtual environment pip install django
Here Insert Picture Description
so Django our virtual environment is now installed

Create a Django project and configuration environment variable :
Create a Project command django-admin startproject School(Note: School project name)
Note: this command is executed where it will create a project in which path
Here Insert Picture DescriptionHere Insert Picture Description
so that we create a Django project
Next we use pycharm open the project
Here Insert Picture Description
the next configuration environment variables (the environment variable environment variables to configure our virtual environment)
to enter the settings pycharm, click on "project: project name" project Interpreter click
Here Insert Picture Description
the gear icon, click the red circle, select Add Local
selected python.exe in our virtual environment
Here Insert Picture Description
click OK
and then use our newly added environment variables
Here Insert Picture Description
see no dj icon on the red cross to show that our environment variable configuration was successful

Python Django project document presents :
Here Insert Picture Description
Here Insert Picture Description
writing a simple Django project (hello world!):

Create a view file: directory described above is to create a built-in directory of the project, in order to achieve today's program, but you need to create a file called views.py in School \ School own
Here Insert Picture Description
writing web logic:
write in the following views.py Code
Here Insert Picture Description
to add the following code to the project document routing
Here Insert Picture Description
startup items:
click the green triangle button in the upper right corner pycharm
Here Insert Picture Description

Here Insert Picture Description
Viewed through a browser program impact:
in the browser address bar http://127.0.0.1:8000/index/to access
Here Insert Picture Description
a simple Django project is successful

Published 21 original articles · won praise 9 · views 9576

Guess you like

Origin blog.csdn.net/Zhang_Chao_1998/article/details/85860532