windos下安装django

Posted 李先生

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了windos下安装django相关的知识,希望对你有一定的参考价值。

一:pip install Django

      安装完以后,运行python manager.py runserver 0.0.0.0:8000报错
 
1):没有安装mysql-python,安装Mysql-python的时候报错没有注册,把下面的代码保存为register.py文件,然后执行python register.py,就可以了
#
# script to register Python 2.0 or later for use with win32all
# and other extensions that require Python registry settings
#
# written by Joakim Loew for Secret Labs AB / PythonWare
#
# source:
# http://www.pythonware.com/products/works/articles/regpy20.htm
#
# modified by Valentine Gogichashvili as described in http://www.mail-archive.com/distutils-sig@python.org/msg10512.html
 
import sys
 
from _winreg import *
 
# tweak as necessary
version = sys.version[:3]
installpath = sys.prefix
 
regpath = "SOFTWARE\\\\Python\\\\Pythoncore\\\\%s\\\\" % (version)
installkey = "InstallPath"
pythonkey = "PythonPath"
pythonpath = "%s;%s\\\\Lib\\\\;%s\\\\DLLs\\\\" % (
    installpath, installpath, installpath
)
 
def RegisterPy():
    try:
        reg = OpenKey(HKEY_CURRENT_USER, regpath)
    except EnvironmentError as e:
        try:
            reg = CreateKey(HKEY_CURRENT_USER, regpath)
            SetValue(reg, installkey, REG_SZ, installpath)
            SetValue(reg, pythonkey, REG_SZ, pythonpath)
            CloseKey(reg)
        except:
            print "*** Unable to register!"
            return
        print "--- Python", version, "is now registered!"
        return
    if (QueryValue(reg, installkey) == installpath and
        QueryValue(reg, pythonkey) == pythonpath):
        CloseKey(reg)
        print "=== Python", version, "is already registered!"
        return
    CloseKey(reg)
    print "*** Unable to register!"
    print "*** You probably have another Python installation!"
 
if __name__ == "__main__":
    RegisterPy()

 

 
2)字符集不对:
 
解决办法:在D:\\Python27\\Lib\\mimetypes.py 的import下添加如下代码
if sys.getdefaultencoding() != \'gbk\': 
    reload(sys) 
    sys.setdefaultencoding(\'gbk\')
 
 
3):安装了Mysql-python但是还是报错,这是因为安装的版本错了,要安装32位的,MySQL-python-1.2.5.win32-py2.7.exe  这里的32位不是指你的操作系统32位,而是Python的
 
4):然后运行的时候还报错:
 
 解决办法,找到D:\\Python27\\lib\\functools.py 这个文件,把第56行的convert这一段替换成下面这一段
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)]
    }

 

然后成功啦
 
 
 

以上是关于windos下安装django的主要内容,如果未能解决你的问题,请参考以下文章

Windos下安装RabbitMQ

Windoes下安装配置flutter环境

在Tomcat的安装目录下conf目录下的server.xml文件中增加一个xml代码片段,该代码片段中每个属性的含义与用途

MySQL 安装与启动

如何在 Django Summernote 中显示编程片段的代码块?

Windows server iis部署Django详细操作