django项目关闭debug就500错误,求帮助

me坤子 发布于 2015/08/13 21:51
阅读 1K+
收藏 0

Traceback (most recent call last):

 File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py", line 112, in get_response

   response = wrapped_callback(request, *callback_args, **callback_kwargs)

 File "/usr/local/lib/python2.7/dist-packages/xadmin/sites.py", line 291, in wrapper

   return self.admin_view(view, cacheable)(*args, **kwargs)

 File "/usr/local/lib/python2.7/dist-packages/django/views/decorators/cache.py", line 52, in _wrapped_view_func

   response = view_func(request, *args, **kwargs)

 File "/usr/local/lib/python2.7/dist-packages/xadmin/sites.py", line 199, in inner

   return view(request, *args, **kwargs)

 File "/usr/local/lib/python2.7/dist-packages/xadmin/views/base.py", line 257, in view

   return handler(request, *args, **kwargs)

 File "/usr/local/lib/python2.7/dist-packages/django/views/decorators/cache.py", line 52, in _wrapped_view_func

   response = view_func(request, *args, **kwargs)

 File "/usr/local/lib/python2.7/dist-packages/xadmin/views/dashboard.py", line 588, in get

   return self.template_response('xadmin/views/dashboard.html', self.get_context())

 File "/usr/local/lib/python2.7/dist-packages/xadmin/views/base.py", line 73, in method

   return filter_chain(filters, len(filters) - 1, _inner_method, *args, **kwargs)

 File "/usr/local/lib/python2.7/dist-packages/xadmin/views/base.py", line 56, in filter_chain

   return filter_chain(filters, token - 1, _inner_method, *args, **kwargs)

 File "/usr/local/lib/python2.7/dist-packages/xadmin/views/base.py", line 56, in filter_chain

   return filter_chain(filters, token - 1, _inner_method, *args, **kwargs)

 File "/usr/local/lib/python2.7/dist-packages/xadmin/views/base.py", line 56, in filter_chain

   return filter_chain(filters, token - 1, _inner_method, *args, **kwargs)

 File "/usr/local/lib/python2.7/dist-packages/xadmin/views/base.py", line 42, in filter_chain

   return func()

 File "/usr/local/lib/python2.7/dist-packages/xadmin/views/base.py", line 55, in _inner_method

   return fm(func if fargs[1] == '__' else func(), *args, **kwargs)

 File "/usr/local/lib/python2.7/dist-packages/xadmin/views/base.py", line 55, in _inner_method

   return fm(func if fargs[1] == '__' else func(), *args, **kwargs)

 File "/usr/local/lib/python2.7/dist-packages/xadmin/views/base.py", line 55, in _inner_method

   return fm(func if fargs[1] == '__' else func(), *args, **kwargs)

 File "/usr/local/lib/python2.7/dist-packages/xadmin/views/base.py", line 67, in _inner_method

   return func(self, *args, **kwargs)

 File "/usr/local/lib/python2.7/dist-packages/xadmin/views/dashboard.py", line 581, in get_context

   context = super(Dashboard, self).get_context()

 File "/usr/local/lib/python2.7/dist-packages/xadmin/views/base.py", line 73, in method

   return filter_chain(filters, len(filters) - 1, _inner_method, *args, **kwargs)

 File "/usr/local/lib/python2.7/dist-packages/xadmin/views/base.py", line 56, in filter_chain

   return filter_chain(filters, token - 1, _inner_method, *args, **kwargs)

 File "/usr/local/lib/python2.7/dist-packages/xadmin/views/base.py", line 56, in filter_chain

   return filter_chain(filters, token - 1, _inner_method, *args, **kwargs)

 File "/usr/local/lib/python2.7/dist-packages/xadmin/views/base.py", line 56, in filter_chain

   return filter_chain(filters, token - 1, _inner_method, *args, **kwargs)

 File "/usr/local/lib/python2.7/dist-packages/xadmin/views/base.py", line 42, in filter_chain

   return func()

 File "/usr/local/lib/python2.7/dist-packages/xadmin/views/base.py", line 55, in _inner_method

   return fm(func if fargs[1] == '__' else func(), *args, **kwargs)

 File "/usr/local/lib/python2.7/dist-packages/xadmin/views/base.py", line 55, in _inner_method

   return fm(func if fargs[1] == '__' else func(), *args, **kwargs)

 File "/usr/local/lib/python2.7/dist-packages/xadmin/views/base.py", line 55, in _inner_method

   return fm(func if fargs[1] == '__' else func(), *args, **kwargs)

 File "/usr/local/lib/python2.7/dist-packages/xadmin/views/base.py", line 67, in _inner_method

   return func(self, *args, **kwargs)

 File "/usr/local/lib/python2.7/dist-packages/xadmin/views/base.py", line 414, in get_context

   self.request.session['nav_menu'] = json.dumps(nav_menu)

 File "/usr/lib/python2.7/json/__init__.py", line 243, in dumps

   return _default_encoder.encode(obj)

 File "/usr/lib/python2.7/json/encoder.py", line 207, in encode

   chunks = self.iterencode(o, _one_shot=True)

 File "/usr/lib/python2.7/json/encoder.py", line 270, in iterencode

   return _iterencode(o, 0)

 File "/usr/lib/python2.7/json/encoder.py", line 184, in default

   raise TypeError(repr(o) + " is not JSON serializable")

TypeError: <django.utils.functional.__proxy__ object at 0x7f35444cd790> is not JSON serializable

<WSGIRequest

path:/,

GET:<QueryDict: {}>,

POST:<QueryDict: {}>,

COOKIES:{'csrftoken': 'zAhMU9LoI5ET266VIoe4SZ6L02Mt46Ut',

'sessionid': 'kzvitj35u9jj0qzhl0978yndw2v6mrtn'},

META:{'CONTEXT_DOCUMENT_ROOT': '/var/www',

'CONTEXT_PREFIX': '',

'DOCUMENT_ROOT': '/var/www',

'GATEWAY_INTERFACE': 'CGI/1.1',

'HTTP_ACCEPT': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8',

'HTTP_ACCEPT_ENCODING': 'gzip, deflate, sdch',

'HTTP_ACCEPT_LANGUAGE': 'zh-CN,zh;q=0.8',

'HTTP_CACHE_CONTROL': 'max-age=0',

'HTTP_CONNECTION': 'keep-alive',

'HTTP_COOKIE': 'csrftoken=zAhMU9LoI5ET266VIoe4SZ6L02Mt46Ut; sessionid=kzvitj35u9jj0qzhl0978yndw2v6mrtn',

'HTTP_HOST': '域名',

'HTTP_USER_AGENT': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/43.0.2357.124 Safari/537.36 QQBrowser/3.7.3773.400',

'PATH_INFO': u'/',

'PATH_TRANSLATED': '/home/xuyukun/newitdb/newitdb/django.wsgi/',

'QUERY_STRING': '',

'REMOTE_ADDR': '115.34.214.156',

'REMOTE_PORT': '61977',

'REQUEST_METHOD': 'GET',

'REQUEST_SCHEME': 'http',

'REQUEST_URI': '/',

'SCRIPT_FILENAME': '/home/xuyukun/newitdb/newitdb/django.wsgi',

'SCRIPT_NAME': u'',

'SERVER_ADDR': '服务器ip',

'SERVER_ADMIN': '邮箱',

'SERVER_NAME': '域名',

'SERVER_PORT': '80',

'SERVER_PROTOCOL': 'HTTP/1.1',

'SERVER_SIGNATURE': '<address>Apache/2.4.7 (Ubuntu) Server at "域名" Port 80</address>\n',

'SERVER_SOFTWARE': 'Apache/2.4.7 (Ubuntu)',

'mod_wsgi.application_group': '域名|',

'mod_wsgi.callable_object': 'application',

'mod_wsgi.enable_sendfile': '0',

'mod_wsgi.handler_script': '',

'mod_wsgi.input_chunked': '0',

'mod_wsgi.listener_host': '',

'mod_wsgi.listener_port': '80',

'mod_wsgi.process_group': '',

'mod_wsgi.queue_start': '1439473136380460',

'mod_wsgi.request_handler': 'wsgi-script',

'mod_wsgi.script_reloading': '1',

'mod_wsgi.version': (3, 4),

'wsgi.errors': <mod_wsgi.Log object at 0x7f35448f7030>,

'wsgi.file_wrapper': <built-in method file_wrapper of mod_wsgi.Adapter object at 0x7f354492f378>,

'wsgi.input': <mod_wsgi.Input object at 0x7f35449875f0>,

'wsgi.multiprocess': True,

'wsgi.multithread': False,

'wsgi.run_once': False,

'wsgi.url_scheme': 'http',

'wsgi.version': (1, 0)}>

加载中
0
x
xlmrmu
八成是字符串类型的问题
me坤子
me坤子
我该用什么思路去排查了,小白一个 求指教
0
x
xiyou

settings.py里边要设置DEBUG=false的时候需要设置下面的变量,

ALLOWED_HOSTS = ['*']

可以把*指定为你自己的域名。不知道楼主的错误是不是因为这个原因引起的。

me坤子
me坤子
不是这个问题
0
yongzhong
yongzhong

json的标准是双引号,单引号进行转换的时候会报错

你试下把数据重新用dict构造然后再解析成json

me坤子
me坤子
谢谢,我去改下试试
0
Kinegratii
Kinegratii
<django.utils.functional.__proxy__ object at 0x7f35444cd790> is not JSON serializable

这个是问题的关键,查了下是因为json无法序列化lazy对象。

Django在url反向解析和国际化/本地化有用到lazy对象。


最重要的是在track中看到比较有用的代码是这个

self.request.session['nav_menu'] = json.dumps(nav_menu)


估计是跟菜单配置有关的东西,检查下配置和xadmin要求的是否一致,特别是上面两方面的内容。如果还是找不出问题,可能是xadmin的问题了,向作者询问下。

me坤子
me坤子
好的,我研究下
Kinegratii
Kinegratii
那个代码是 self.request.session['nav_menu'] = json.dumps(nav_menu)
0
山下狮子
山下狮子

你这个关不关debug都会报错。

楼上正解吗,错误提示那么明显。

序列化问题,你估计序列化了基本类型以外的东西


File "/usr/local/lib/python2.7/dist-packages/xadmin/views/base.py", line 414, in get_context

   self.request.session['nav_menu'] = json.dumps(nav_menu)


nav_menu是个啥子玩意

0
x
xlmrmu
单元测试
0
s
scuzz

今天也遇到这个问题了,将配置文件中DEBUG = conf.debug == 'yes' 改成no之后就好了

me坤子
me坤子
那错误页没法定义了,而且500会暴露很多信息
返回顶部
顶部