ubuntu18.04 - Creating your first Django project

 step1:

Installing the Virtual Environment:

sudo pip3 install virtualenv # install virtual environment 
sudo pip3 install virtualenvwrapper # install the expansion pack virtual environment
.bashrc file in the home directory # editor and add the following three lines of code at the bottom

  export WORKON_HOME = $ HOME / .virtualenvs # virtualenvwrapper environment specified directory
  export VIRTUALENVWRAPPER_PYTHON = / usr / bin / python3.6 # virtualenvwrapper to create a virtual environment to specify which version of python by
  source ~ / .local / bin / virtualenvwrapper.sh

 

  # Use source .bashrc to take effect

 

step2:

cp ~ sudo / .local / bin / virtualenv / usr / bin / 

# Without this step, create a virtual environment will be reported when the following error:
ERROR: virtualenvwrapper could not virtualenv in the Find your path

 

step3:

Create a virtual environment (and related operations):

mkvirtualenv django2.2 # django2.2 virtual environment name 

-----------------

workon django2.2 # to enter the virtual environment

workon space + 'double-click the tab' # on the machine View the virtual environment

deactivate # exit the virtual environment

 

step4:

Django installation environment:

pip install django==2.2

 

step5:

Create a django project:

django-admin startproject mysite # mysite project name

Project directory as follows:

manage.py - Project Management Files

__init__.py - Description mysite This directory is a package python

setting.py - project profile

urls.py - carried url routing configuration

wsgi.py - Entrance web server and interact with django

 

step6:

Create a django application:

 python manage.py startapp app1 # app1 application name

Application directory as follows:

admin.py - Administration File

Write content databases and projects - models.py

tests.py - write test code file

views.py - View File (reception request, a process)

 

step7:

Registration Application --- Add the app name to INSTALLED_APPS of configuration items setting.py

 

step8:

Run the project:

python manage.py runserver

The browser address bar enter: http://127.0.0.1:8000/

 

Guess you like

Origin www.cnblogs.com/Asgard-l/p/11302117.html