Django错误大汇总
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',
]
Django错误大汇总的更多相关文章
- 大礼包!ANDROID内存优化(大汇总)
写在最前: 本文的思路主要借鉴了2014年AnDevCon开发者大会的一个演讲PPT,加上把网上搜集的各种内存零散知识点进行汇总.挑选.简化后整理而成. 所以我将本文定义为一个工具类的文章,如果你在A ...
- android app性能优化大汇总(内存性能优化)
转载请注明本文出自大苞米的博客(http://blog.csdn.net/a396901990),谢谢支持! 写在最前: 本文的思路主要借鉴了2014年AnDevCon开发者大会的一个演讲PPT,加上 ...
- ANDROID内存优化——大汇总(转)
原文作者博客:转载请注明本文出自大苞米的博客(http://blog.csdn.net/a396901990),谢谢支持! ANDROID内存优化(大汇总——上) 写在最前: 本文的思路主要借鉴了20 ...
- ANDROID内存优化(大汇总——中)
转载请注明本文出自大苞米的博客(http://blog.csdn.net/a396901990),谢谢支持! 写在最前: 本文的思路主要借鉴了2014年AnDevCon开发者大会的一个演讲PPT,加上 ...
- ANDROID内存优化(大汇总——上)
转载请注明本文出自大苞米的博客(http://blog.csdn.net/a396901990),谢谢支持! 写在最前: 本文的思路主要借鉴了2014年AnDevCon开发者大会的一个演讲PPT,加上 ...
- C/C++ 笔试、面试题目大汇总 转
C/C++ 笔试.面试题目大汇总 这些东西有点烦,有点无聊.如果要去C++面试就看看吧.几年前网上搜索的.刚才看到,就整理一下,里面有些被我改了,感觉之前说的不对或不完善. 1.求下面函数的返回值( ...
- 转 C语言面试题大汇总
转 C语言面试题大汇总,个人觉得还是比较全地!!! \主 题: C语言面试题大汇总,个人觉得还是比较全地!!! 作 者: free131 (白日?做梦!) 信 誉 值: 100 ...
- java面试笔试大汇总
java面试笔试题大汇总5 JAVA相关基础知识 1.面向对象的特征有哪些方面 1.抽象:2.继承:3.封装:4. 多态性: 2.String是最基本的数据类型吗? 基本数据类型包括byte.int. ...
- 实用的vue插件大汇总
Vue是一个构建数据驱动的 web 界面的渐进式框架.Vue.js 的目标是通过尽可能简单的 API 实现响应的数据绑定和组合的视图组件特别整理了常用的vue插件,来了个大汇总,方便查找使用,便于工作 ...
随机推荐
- c# WebService SOAP及Rest调用
SOAP及Rest的调用区别参照如下: REST似乎在一夜间兴起了,这可能引起一些争议,反对者可以说REST是WEB诞生之始甚而是HTTP出现之日就相伴而生的原则.但是毋庸置疑的事实是,在Google ...
- easyui 控件获取焦点方式
针对easyui控件前端组织的dom做分析,如下: combo/combobox/combogrid类似结构如下: <input class="easyui-datebox dateb ...
- Spark RDD中的aggregate函数
转载自:http://blog.csdn.net/qingyang0320/article/details/51603243 针对Spark的RDD,API中有一个aggregate函数,本人理解起来 ...
- 10个基于 JavaScript 的 WYSIWYG 编辑器
COMSHARP CMS 写道:在线编辑内容的时候,那些基于 JavaScript 的编辑器帮了我们大忙,这些所见即所得(WYSIWYG)编辑器,给我们提供了类似 Office 的操作体验.如今,任何 ...
- js刷题:leecode 25
原题:https://leetcode.com/problems/reverse-nodes-in-k-group/ 题意就是给你一个有序链表.如1->2->3->4->5,还 ...
- ubuntu之安装pycharm编辑器
pycharm是Java写的,运行需要Java环境. 安装java jdk sudo add-apt-repository ppa:webupd8team/java sudo apt-get upda ...
- py,pyc,pyw文件的区别和使用
熟悉python编程的都知道,python三种最常见的py文件格式,.py,.pyc,.pyw,下面说一说它们各自的使用. py文件 python最常见的文件,是python项目的源码: 文件执行时l ...
- CSU 1356 Catch
原题链接:http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1356 题目需要我们判断给定图在某一步是否会有可能出现在所有节点.首先,我们不妨假设给定图 ...
- 【PAT】1001. A+B Format (20)
1001. A+B Format (20) Calculate a + b and output the sum in standard format -- that is, the digits m ...
- 【LOJ】#2010. 「SCOI2015」小凸解密码
题解 断环为链,把链复制两份 用set维护一下全是0的区间,然后查找x + n / 2附近的区间,附近各一个过不去,最后弃疗了改为查附近的两个,然后过掉了= = 熟练掌握stl的应用,你值得拥有(雾 ...