tags:

views:

657

answers:

2

I have deployed my django app using Apache and mod_wsgi. All of the settings load fine, but when I redirect the user to the login page, I get the following error:

  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__'

With or with out the login redirect in place, I get this error when trying to load the /admin site.

  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__'

I have another django powered site on this same server that runs fine even in the admin site. I am stumped as to why this behavior has popped up on this site but not on the other.

Any help would be greatly appreciated!

A: 

Is your app in an archive, such as a .zip or .egg file? If so, modules loaded from it won't have __file__ set.

John Millikin
Nope, not in an archive. Good info to know though!
joshcody
+1  A: 

This is a bit of an old post, but I found it so someone else might.

That urlresolver error in django happens when there's a problem compiling your view (or something imported by your view). Sadly, the stack trace seems to be incomplete; what comes up in the browser gives absolutely no indication of where the problem really lies.

Here's how I fixed my issue: 1) Go into the top level directory for your django app (the one with settings.py and manage.py) 2) run : python manage.py shell 3) that will drop you into a python interpreter. From there, do : import appname.viewWithProblems 4) that should throw an Exception that includes the stack trace you'll need to find the problem.

Hope someone else out there doesn't have the night I had last night!

Matt Bosworth