开发者

Django ValueError at /admin/

开发者 https://www.devze.com 2022-12-12 11:24 出处:网络
I am running Django with mod_python on a Red Hat Linux box in production. A little while ago, for a reason unknown 开发者_运维技巧to me, the admin stopped working, throwing a 500 error. The error is a

I am running Django with mod_python on a Red Hat Linux box in production. A little while ago, for a reason unknown 开发者_运维技巧to me, the admin stopped working, throwing a 500 error. The error is as follows:

ValueError at /admin/
Empty module name
Request Method: GET
Exception Type: ValueError
Exception Value: 
Empty module name
Exception Location: /usr/local/lib/python2.6/site-packages/django/utils/importlib.py in import_module, line 35
Python Executable: /usr/bin/python
Python Version: 2.6.2

Has anyone encountered this before? I have absolutely no idea how to fix this problem.

Thank you for any help.


I was just debugging this problem. The error arises when Django is attempting to set up the template context processors, and the root cause was a definition which should have been a tuple but was actually a string.

This is what I had in my config file:

TEMPLATE_CONTEXT_PROCESSORS = (
'django.core.context_processors.auth'
)

This is what I should have had:

TEMPLATE_CONTEXT_PROCESSORS = (
'django.core.context_processors.auth',
)

Without the trailing comma, Python treats the value of the variable as a string. Thus, Django code which looks like this:

for path in settings.TEMPLATE_CONTEXT_PROCESSORS:
    i = path.rfind('.')
    module,attr = path[:i],path[i+1:]

the first value of 'path' is 'd', not 'django.core.context_processors.auth'. This leads the value of 'i' to be -1 and thus the value of 'module' to be empty.

Make sure that all of the tuple-like things in your Django config are actually tuples, which means if they have a single value, they still need a trailing comma.

0

精彩评论

暂无评论...
验证码 换一张
取 消