一、下载
二、安装
默认已经安装了Python,这里就只将django的安装
(1)下载django压缩包后,解压并且将文件夹放入python的安装目录中,然后进入django目录,执行 python setup.py install,然后开始安装,安装完成后Django会被安装到python的Lib下site-packages中
(2)配置环境,将python安装目录下的Script和site-packages中的django都放入系统环境变量中。
比如我的两个路径是:D:\program files\python2.7.0\Scripts; 和 D:\program files\python2.7.0\Lib\site-packages\Django-1.9.7-py2.7.egg\django;
(3)检查是否安装成功
命令行中执行以下命令:
python
import django
django.get_version()
说明安装成功
三、第一个django工程
在工程目录下打开命令框,执行 django-admin startproject HelloWorld
在工程目录下出现项目文件夹,结构如下:
|-- HelloWorld | |-- __init__.py | |-- settings.py | |-- urls.py | `-- wsgi.py `-- manage.py
说明:
(1)HelloWorld:项目的容器
(2)manage.py:一个实用的命令行工具,可让你以各种方式与该Django项目进行交互。
(3)HelloWorld/__init__.py:一个空文件,告诉Python该目录是一个Python包
(4)HelloWorld/settings.py:该Django项目的设置/配置。
(5)HelloWorld/urls.py:该Django项目的URL声明,一份由Django驱动的网站“目录”
(6)HelloWorld/wsgi.py:一个WSGI兼容的Web服务器的入口,以便运行你的项目
四、启动服务器
在HelloWorld目录下运行命令框,执行
python manage.py runserver 8001
打开浏览器输入:http://localhost:8001 或者 http://127.0.0.1:8001/
说明创建成功
五、可能遇到的问题
在开启服务器时报错
解决方案:
找到Python\Lib\fuctools.py
将里面的代码:
convert = {
'__lt__': [('__gt__', lambda self, other: other < self),
('__le__', lambda self, other: not other < self),
('__ge__', lambda self, other: not self < other)],
'__le__': [('__ge__', lambda self, other: other <= self),
('__lt__', lambda self, other: not other <= self),
('__gt__', lambda self, other: not self <= other)],
'__gt__': [('__lt__', lambda self, other: other > self),
('__ge__', lambda self, other: not other > self),
('__le__', lambda self, other: not self > other)],
'__ge__': [('__le__', lambda self, other: other >= self),
('__gt__', lambda self, other: not other >= self),
('__lt__', lambda self, other: not self >= other)]
}
convert = {
'__lt__': [('__gt__', lambda self, other: not (self < other or self == other)),
('__le__', lambda self, other: self < other or self == other),
('__ge__', lambda self, other: not self < other)],
'__le__': [('__ge__', lambda self, other: not self <= other or self == other),
('__lt__', lambda self, other: self <= other and not self == other),
('__gt__', lambda self, other: not self <= other)],
'__gt__': [('__lt__', lambda self, other: not (self > other or self == other)),
('__ge__', lambda self, other: self > other or self == other),
('__le__', lambda self, other: not self > other)],
'__ge__': [('__le__', lambda self, other: (not self >= other) or self == other),
('__gt__', lambda self, other: self >= other and not self == other),
('__lt__', lambda self, other: not self >= other)]
}