windows中Django安装教程

一、下载


python下载地址:https://www.python.org/downloads/

Django下载地址:https://www.djangoproject.com/download/


二、安装


默认已经安装了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/




说明创建成功


五、可能遇到的问题


在开启服务器时报错

Django RuntimeError: maximum recursion depth exceeded


解决方案:

找到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)]
}

  • 1
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值