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插件,来了个大汇总,方便查找使用,便于工作 ...
随机推荐
- Why are Eight Bits Enough for Deep Neural Networks?
Why are Eight Bits Enough for Deep Neural Networks? Deep learning is a very weird technology. It evo ...
- 超酷动态图片展示墙JS特效制作方法
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- JQuery和Servlet来实现跨域请求
在网上看到很多的JQuery跨域请求的文章,比较有意思.这里我发表一个Servlet与JQuery配置实现跨域的代码,供大家参考.不足之处请指教 原理:JavaScript的Ajax不可以跨域,但是可 ...
- flume监控一个linux指定的一个文件夹的文件信息
1.编辑一个配置文件 flume-app.conf 拷贝至fulme的安装目录的conf下 # The configuration file needs to define the sources, ...
- 用Vue来实现图片上传多种方式
没有业务场景的功能都是耍流氓,那么我们先来模拟一个需要实现的业务场景.假设我们要做一个后台系统添加商品的页面,有一些商品名称.信息等字段,还有需要上传商品轮播图的需求. 我们就以Vue.Element ...
- 吐泡泡(2018年全国多校算法寒假训练营练习比赛(第二场)+栈模拟)+Plug-in(codeforces81A+栈模拟)
吐泡泡题目链接:https://www.nowcoder.com/acm/contest/74/A 题目: 思路: 这种题目当初卡了我很久,今天早训时遇到一个一样得题,一眼就想到用栈模拟,就又回来把这 ...
- HDU 2067 小兔的棋盘 (模拟)
题目链接 Problem Description 小兔的叔叔从外面旅游回来给她带来了一个礼物,小兔高兴地跑回自己的房间,拆开一看是一个棋盘,小兔有所失望.不过没过几天发现了棋盘的好玩之处.从起点(0, ...
- LeetCode之数据流中第一个唯一的数字
使用一个Map维护数字出现的次数,使用一个链表维护只出现一次的数,使用一个变量记录是否找到过终止数字. AC代码: public class Solution { /* * @param : a co ...
- Python3中的SocketServer
socket并不能多并发,只能支持一个用户,socketserver 简化了编写网络服务程序的任务,socketserver是socket的在封装.socketserver在python2中为Sock ...
- 高性能优秀的服务框架-dubbo介绍
先来了解一下这些年架构的变化,下面的故事是我编的.... "传统架构":很多年前,刚学完JavaWeb开发的我凭借一人之力就开发了一个网站,网站 所有的功能和应用都集中在一起,方便 ...