ViewDoesNotExist:尝试登录模块django.contrib.auth.views。错误是:'module'对象没有属性'__file__'

时间:2009-08-28 20:56:32

标签: django

我使用Apache和mod_wsgi部署了我的django应用程序。所有设置加载正常,但是当我将用户重定向到登录页面时,我收到以下错误:

  File "/opt/ActivePython-2.6/lib/python2.6/site-packages/django/core/handlers/base.py", line 83, in get_response
    request.path_info)

  File "/opt/ActivePython-2.6/lib/python2.6/site-packages/django/core/urlresolvers.py", line 186, in resolve
    sub_match = pattern.resolve(new_path)

  File "/opt/ActivePython-2.6/lib/python2.6/site-packages/django/core/urlresolvers.py", line 125, in resolve
    return self.callback, args, kwargs

  File "/opt/ActivePython-2.6/lib/python2.6/site-packages/django/core/urlresolvers.py", line 137, in _get_callback
    raise ViewDoesNotExist, "Tried %s in module %s. Error was: %s" % (func_name, mod_name, str(e))

ViewDoesNotExist: Tried login in module django.contrib.auth.views. Error was: 'module' object has no attribute '__file__'

使用或不使用登录重定向,我在尝试加载/ admin网站时收到此错误。

  File "/opt/ActivePython-2.6/lib/python2.6/site-packages/django/core/handlers/base.py", line 92, in get_response
    response = callback(request, *callback_args, **callback_kwargs)

  File "/opt/ActivePython-2.6/lib/python2.6/site-packages/django/contrib/admin/sites.py", line 164, in wrapper
    return self.admin_view(view)(*args, **kwargs)

  File "/opt/ActivePython-2.6/lib/python2.6/site-packages/django/contrib/admin/sites.py", line 155, in inner
    return self.login(request)

  File "/opt/ActivePython-2.6/lib/python2.6/site-packages/django/views/decorators/cache.py", line 44, in _wrapped_view_func
    response = view_func(request, *args, **kwargs)

  File "/opt/ActivePython-2.6/lib/python2.6/site-packages/django/contrib/admin/sites.py", line 253, in login
    return self.display_login_form(request, message)

  File "/opt/ActivePython-2.6/lib/python2.6/site-packages/django/contrib/admin/sites.py", line 349, in display_login_form
    'title': _('Log in'),

  File "/opt/ActivePython-2.6/lib/python2.6/site-packages/django/utils/translation/__init__.py", line 62, in ugettext
    return real_ugettext(message)

  File "/opt/ActivePython-2.6/lib/python2.6/site-packages/django/utils/translation/trans_real.py", line 286, in ugettext
    return do_translate(message, 'ugettext')

  File "/opt/ActivePython-2.6/lib/python2.6/site-packages/django/utils/translation/trans_real.py", line 276, in do_translate
    _default = translation(settings.LANGUAGE_CODE)

  File "/opt/ActivePython-2.6/lib/python2.6/site-packages/django/utils/translation/trans_real.py", line 194, in translation
    default_translation = _fetch(settings.LANGUAGE_CODE)

  File "/opt/ActivePython-2.6/lib/python2.6/site-packages/django/utils/translation/trans_real.py", line 181, in _fetch
    apppath = os.path.join(os.path.dirname(app.__file__), 'locale')

AttributeError: 'module' object has no attribute '__file__'

我在同一台服务器上有另一个django支持的站点,即使在管理站点也运行良好。我很难过为什么这个行为在这个网站上出现但在另一个网站上却没有出现。

非常感谢任何帮助!

2 个答案:

答案 0 :(得分:6)

这是一个旧帖子,但我发现它可能是其他人的。

当编译视图(或视图导入的内容)出现问题时,django中的urlresolver错误会发生。可悲的是,堆栈跟踪似乎不完整;浏览器中出现的内容绝对没有说明问题究竟在哪里。

以下是我解决问题的方法:

  1. 进入django应用程序的顶级目录(带有settings.py和manage.py的应用程序)
  2. 运行:python manage.py shell
  3. 会让你进入python解释器。从那里,执行:import appname.viewWithProblems
  4. 应抛出一个Exception,其中包含您需要找到问题的堆栈跟踪。
  5. 希望那里的其他人没有我昨晚的夜晚!

答案 1 :(得分:0)

您的应用是否存档,例如.zip或.egg文件?如果是这样,从其加载的模块将不会设置__file__