I. 安装django
pip install django==1.9 ::(如果不指定版本号,则会自动安装最新版本) pip install django
II. 生成项目:
django-admin.py startproject mysite
III.运行网站:
::默认端口8000 mange.py runserver ::指定端口 manage.py runserver 8080 ::指定IP地址,指定端口 manage.py runserver 0.0.0.0:8080
IV.创建一个应用:
manage.py startapp polls
在这里说明一下,project与app的区别:
一个project可以包含多个app,一个app可以被多个project使用。
An app is a Web application that does something – e.g., a Weblog system, a database of public records or a simple poll app.
A project is a collection of configuration and apps for a particular website. A project can contain multiple apps. An app can be in multiple projects.
此时项目的文件目录结构为:
https://docs.djangoproject.com/en/1.9/intro/tutorial01/
install apache2 and mod-wsgi
1 sudo apt-get install apache2 2 3 # Python 2 4 sudo apt-get install libapache2-mod-wsgi 5 6 # Python 3 7 sudo apt-get install libapache2-mod-wsgi-py3
active the site
$ sudo
a2ensite sitename.conf
sudo
service apache2 restart
sudo
service apache2 reload
sudo
service apache2 start
sudo
service apache2 stop
获取属性:
from attendence.models import * Employee._meta.get_fields() Employee._meta.get_all_field_names() #removed in django 1.10