Django app在404上是500

时间:2011-11-20 07:32:16

标签: django

我有一个Django项目,里面有一个应用程序。

如果我将调试设置为True,并且我在/ sdfsdfsf这样的网址中写入,则会出错

Using the URLconf defined in website.urls, Django tried these URL patterns, in this order:
...
The current URL, dsd, didn't match any of these.
You're seeing this error because you have DEBUG = True in your Django settings file. Change that to False, and Django will display a standard 404 page.

然后我编辑settings.py来关闭Debug,但现在我得到500错误。我查看错误配置并获取此信息;

mod_wsgi (pid=17601): Exception occurred processing WSGI script '/var/websites/xxxxx/website/django.wsgi'.
Traceback (most recent call last):
    File "/usr/local/lib/python2.6/dist-packages/django/core/handlers/wsgi.py", line 272, in __call__
        response = self.get_response(request)
    File "/usr/local/lib/python2.6/dist-packages/django/core/handlers/base.py", line 153, in get_response
        response = self.handle_uncaught_exception(request, resolver, sys.exc_info())
    File "/usr/local/lib/python2.6/dist-packages/django/core/handlers/base.py", line 218, in handle_uncaught_exception
        return callback(request, **param_dict)
    File "/usr/local/lib/python2.6/dist-packages/django/utils/decorators.py", line 93, in _wrapped_view
        response = view_func(request, *args, **kwargs)
    File "/usr/local/lib/python2.6/dist-packages/django/views/defaults.py", line 30, in server_error
        t = loader.get_template(template_name) # You need to create a 500.html template.
    File "/usr/local/lib/python2.6/dist-packages/django/template/loader.py", line 157, in get_template
        template, origin = find_template(template_name)
    File "/usr/local/lib/python2.6/dist-packages/django/template/loader.py", line 128, in find_template
        loader = find_template_loader(loader_name)
    File "/usr/local/lib/python2.6/dist-packages/django/template/loader.py", line 95, in find_template_loader
        mod = import_module(module)
    File "/usr/local/lib/python2.6/dist-packages/django/utils/importlib.py", line 35, in import_module
        __import__(name)
    File "/usr/local/lib/python2.6/dist-packages/django/template/loaders/app_directories.py", line 23, in <module>
        raise ImproperlyConfigured('ImportError %s: %s' % (app, e.args[0]))
    ImproperlyConfigured: ImportError cardir: No module named cardir

cardir是项目中我的应用程序的名称。但是,如果去一个不是404(如/或/ about)的页面,它可以正常工作,所以它可以获得cardir。我觉得还有其他事情发生了。

结构;

# ls
cardir  django.wsgi  __init__.py  __init__.pyc  manage.py  settings.py  settings.pyc  static  templates  urls.py  urls.pyc

# cd templates/ && ls
404.html  500.html  base.html  index.html

1 个答案:

答案 0 :(得分:2)

检查404.html中是否有错误。我前段时间遇到过类似问题。