1.安装django报错解决方案  

找到第一条报错信息:
  File "c:\users\chenwei\envs\testvir2\lib\site-packages\pip\basecommand.py", line 215, in main status = self.run(options, args)    
  出错原因:UnicodeEncodeError: 'ascii' codec can't encode character u'\u258f' in position 8: ordinal not in range(128)
  在报错文件:c:\users\chenwei\envs\testvir2\lib\site-packages\pip\basecommand.py 中加如下代码:

import sys
reload(sys)
sys.setdefaultencoding('gbk')

2.错误2:RuntimeError: maximum recursion depth exceeded

解决方案:
To fix the problem replace this (about line 56 in 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)]
}
to that:
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)]
}

3.在python中run manage.py 链接数据库报错:No name mysqlDB

解决方案:pip install mysql-python

4.安装mysql-python报错

错误提示:
    error: command '"C:\Users\chenwei\AppData\Local\Programs\Common\Microsoft\Visual C++ for Python\9.0\VC\Bin\amd64\cl.exe"' failed with exit status2

解决方案:
http://www.lfd.uci.edu/~gohlke/pythonlibs/#mysql-python下载对应的包版本 pip2 install MySQL_python-1.2.5-cp27-none-win_amd64.whl
注意:cp27说明要用python2.7来安装,所以要用pip2

5.执行python2 manage.py runserver 0.0.0.0:8000出错

Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "C:\Python27\lib\site-packages\django\core\management\__init__.py", line 363, in execute_from
utility.execute()
File "C:\Python27\lib\site-packages\django\core\management\__init__.py", line 355, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "C:\Python27\lib\site-packages\django\core\management\base.py", line 283, in run_from_argv
self.execute(*args, **cmd_options)
File "C:\Python27\lib\site-packages\django\core\management\commands\runserver.py", line 62, in exe
super(Command, self).execute(*args, **options)
File "C:\Python27\lib\site-packages\django\core\management\base.py", line 330, in execute
output = self.handle(*args, **options)
File "C:\Python27\lib\site-packages\django\core\management\commands\runserver.py", line 101, in ha
self.run(**options)
File "C:\Python27\lib\site-packages\django\core\management\commands\runserver.py", line 110, in ru
autoreload.main(self.inner_run, None, options)
File "C:\Python27\lib\site-packages\django\utils\autoreload.py", line 341, in main
reloader(wrapped_main_func, args, kwargs)
File "C:\Python27\lib\site-packages\django\utils\autoreload.py", line 312, in python_reloader
exit_code = restart_with_reloader()
File "C:\Python27\lib\site-packages\django\utils\autoreload.py", line 294, in restart_with_reloade
str_value = force_bytes(new_environ[key], encoding=encoding)
File "C:\Python27\lib\site-packages\django\utils\encoding.py", line 124, in force_bytes
return s.decode('utf-8', errors).encode(encoding, errors)
File "C:\Python27\lib\encodings\utf_8.py", line 16, in decode
return codecs.utf_8_decode(input, errors, True)
UnicodeDecodeError: 'utf8' codec can't decode byte 0xd4 in position 15: invalid continuation byte

解决方案:

在manage.py 开头加上
import sys
reload(sys)
sys.setdefaultencoding('utf-8')

6.当创建的app比较多时,将多个app存放在一个文件夹apps下,提示找不到文件路径

  python manage.py runserver 0.0.0.0:8000

  解决方案:

在settins文件中,添加sys.path.insert(0, os.path.join(BASE_DIR, 'apps')) 

7.Django “Cannot add or update a child row: a foreign key constraint fails”

  解决方案:

settins下
DATABASES = {
'default': {
...
'OPTIONS': {
"init_command": "SET foreign_key_checks = 0;",
},
}
}

8.通过源码安装xadmin,执行manage.py时,报找不到xadmin模块

解决方案:将xadmin添加到搜索路径下。

9.django.core.exceptions.ImproperlyConfigured: Application names aren't unique, duplicates: my_app01

 解决方案一:

    在settings中,删除掉你注册的应用:

 解决方案二:

   找到你所写的应用app01---->把apps.py文件中的代码全部注释掉。即可解决问题 

10.'WSGIRequest' object has no attribute 'user'

  将settings中配置的MIDDLEWARE改为MIDDLEWARE_CLASSES

MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]

  

最新文章

  1. android两种基本联网方式与一种第三方开源项目的使用
  2. Python字典实现三级菜单
  3. 开源分布式实时计算引擎 Iveely Computing 之 安装部署(2)
  4. JQuery 选中Radio
  5. lassen项目启动
  6. Web服务器控件表
  7. 如何给你的VS2010添加创建文件后的头注释
  8. bootstrap基本标签总结[转]
  9. Line Painting
  10. yaml 1.6 操作
  11. 如何在VC中显示透明背景位图
  12. JVM类加载原理学习笔记
  13. 2018-4-25 html基础知识
  14. 【转载】tolua之wrap文件的原理与使用
  15. SQL 语句中 where 条件后 写上1=1 的意思
  16. Python全栈开发之路 【第三篇】:Python基础之字符编码和文件操作
  17. CSS expression属性
  18. JSON数据格式解析
  19. df、du、fdisk
  20. SpringBoot2 配置

热门文章

  1. 【BZOJ】2440: [中山市选2011]完全平方数
  2. Oracle数据库语句
  3. 爬虫实战--利用Scrapy爬取知乎用户信息
  4. 美团实习Java岗面经,已拿offer
  5. weblogic性能监控
  6. 【Python学习】csv库
  7. 73.Vivado使用误区与进阶——在Vivado中实现ECO功能
  8. git@oschina.net源代码管理使用日记【转】
  9. ltib安装过程中遇到好多问题,从网上转来的好多份总结
  10. screen命令使用方法【转】