A description, Django framework
Released in 2005, the use of open-source framework written in Python language
Early on Django to do the main news and content management
A heavyweight Python Web framework, Django is equipped with the most commonly used components
(A) Installation:
1. Installation Online:
- $ Sudo pip3 install django # (install the latest version of django)
- $ Sudo pip3 install django [== version]
$ sudo pip3 install django==1.11.8
(To install the specified version of django)
2. Offline installation:
- Download the installation package:
- Offline installation package
$ tar -xvf Django-1.11.8.tar.gz
$ cd Django-1.11.8
$ sudo python3 setup.py install
3. wheel mounted offline
Download the installation package:
pip3 download -d /home/weimz/django_packs django==1.11.8
Offline installation package
$ pip3 install Django-1.11.8.whl
(B) Django unloading: $ pip3 uninstall django
(C) Django development environment:
- Django 1.11.x supports Python 2.7, 3.4, 3.5 and 3.6 (Long Term Support LTS)
- Note: Django 1.11.x does not support Python 3.7
Two, Django development framework
(A) create command items
$ Django-ADMIN startproject Project Name
如:$ django-admin startproject mywebsite1
run:$ cd mywebsite1 $ python3 manage.py runserver # 或 $ python3 manage.py runserver 5000 # 指定只能本机使用127.0.0.1的5000端口访问本机
The directory structure (B) Django project
Django-ADMIN startproject mywebsite1 $
$ Tree mywebsite1 / work
mywebsite1 /
├── manage.py # project management documents
└── mywebsite1
├── __init__.py
├── settings.py # project configuration file
DEBUG = True
ALLOWED_HOST = [ ]
TIME_ZONE = 'UTC' # 'Asia / of Shanghai'
LANGUAGE_CODE = 'Hans-ZH' # 'SU-EN'
base_dir = Bureau of the current location of the path
the ROOT_URLCONF = 'mywebsite1.urls'
├── the urls.py primary # routing configuration file
http: // 127.0.0.1 (: 8000) ? / path a = ( query) # (pieces of information urls)
route: The
main routing configuration file
#file: urls.py
Import django.conf.urls URL from
urlpattrens = [
URL (R & lt '^ page, views.page_view'),
# Note: If a page match is successful, the need to page1 and page2 added after skip & symbol
url (r '^ page1 , views.page1_view '),
URL (R & lt' ^ PAGE2, views.page2_view '),
# / Data / 2018 /. 1/12 is -> data_view (REQ,' 2018 ','. 1 ',' 12 is') is a constant parameter string
URL (R & lt '^ DATE / (\. 4 {D} / (\ D {1,2}) / (\ + D), views.page_view'),
# / Person / Xiaoming / 35 -> person_view (REQ, name = 'xiaoming', age = '35 ') pass keyword parameters, the parameter must be a string
url (r' ^ person / ( ? P <name> \ w +) / (? P <age> \ d +), views .page_view '),
………………
]
└── wsgi.py #wsgi layout file
Project directory structure elucidation:
manage.py
This file is the main program of project management for the development of operational management of the project during the development phase of modal
manage.py
sub-command includes project management, such as:
- python3 manage.py the runserver to start the service
- python3 manage.py startapp create an application
- python3 manage.py migrate database migration