WebFaction
Community site: login faq

When setting DEBUG=True Django returned a 500 error. ALLOWED_HOSTS are set, static files are served correctly,...all should be in order.

After a bit of digging it seems related to admin.autodiscover() in urls.py. The problem is fixed when I uncomment admin.autodiscover(). The website works but I loose access to the admin interface since admin.autodiscover is left out.

#urls.py
from django.conf import settings
from django.conf.urls.static import static
from django.conf.urls import patterns, include, url
from django.contrib.sitemaps import GenericSitemap
from django.contrib.sitemaps.views import sitemap
from django.contrib import sitemaps
from django.core.urlresolvers import reverse

from django.contrib import admin
admin.autodiscover()

I'm not quite sure what's going on here. Anyone know how to fix this issue?

Thanks,

Error log
    [Thu Dec 18 09:53:24 2014] [error] [client 127.0.0.1] mod_wsgi (pid=26500): Exception occurred processing WSGI script '/home/nnn/webapps/ecommerce/src/ecommerce/wsgi.py'.

[Thu Dec 18 09:53:24 2014] [error] [client 127.0.0.1] Traceback (most recent call last):

[Thu Dec 18 09:53:24 2014] [error] [client 127.0.0.1]   File "/home/nnn/webapps/ecommerce/lib/python2.7/django/core/handlers/wsgi.py", line 206, in __call__

[Thu Dec 18 09:53:24 2014] [error] [client 127.0.0.1]     response = self.get_response(request)

[Thu Dec 18 09:53:24 2014] [error] [client 127.0.0.1]   File "/home/nnn/webapps/ecommerce/lib/python2.7/django/core/handlers/base.py", line 194, in get_response

[Thu Dec 18 09:53:24 2014] [error] [client 127.0.0.1]     response = self.handle_uncaught_exception(request, resolver, sys.exc_info())

[Thu Dec 18 09:53:24 2014] [error] [client 127.0.0.1]   File "/home/nnn/webapps/ecommerce/lib/python2.7/django/core/handlers/base.py", line 232, in handle_uncaught_exception

[Thu Dec 18 09:53:24 2014] [error] [client 127.0.0.1]     if resolver.urlconf_module is None:

[Thu Dec 18 09:53:24 2014] [error] [client 127.0.0.1]   File "/home/nnn/webapps/ecommerce/lib/python2.7/django/core/urlresolvers.py", line 360, in urlconf_module

[Thu Dec 18 09:53:24 2014] [error] [client 127.0.0.1]     self._urlconf_module = import_module(self.urlconf_name)

[Thu Dec 18 09:53:24 2014] [error] [client 127.0.0.1]   File "/home/nnn/webapps/ecommerce/lib/python2.7/django/utils/importlib.py", line 40, in import_module

[Thu Dec 18 09:53:24 2014] [error] [client 127.0.0.1]     __import__(name)

[Thu Dec 18 09:53:24 2014] [error] [client 127.0.0.1]   File "/home/nnn/webapps/ecommerce/src/ecommerce/urls.py", line 13, in <module>

[Thu Dec 18 09:53:24 2014] [error] [client 127.0.0.1]     admin.autodiscover()

[Thu Dec 18 09:53:24 2014] [error] [client 127.0.0.1]   File "/home/nnn/webapps/ecommerce/lib/python2.7/django/contrib/admin/__init__.py", line 29, in autodiscover

[Thu Dec 18 09:53:24 2014] [error] [client 127.0.0.1]     import_module('%s.admin' % app)

[Thu Dec 18 09:53:24 2014] [error] [client 127.0.0.1]   File "/home/nnn/webapps/ecommerce/lib/python2.7/django/utils/importlib.py", line 40, in import_module

[Thu Dec 18 09:53:24 2014] [error] [client 127.0.0.1]     __import__(name)

[Thu Dec 18 09:53:24 2014] [error] [client 127.0.0.1]   File "/home/nnn/webapps/ecommerce/src/orders/admin.py", line 3, in <module>

[Thu Dec 18 09:53:24 2014] [error] [client 127.0.0.1]     from .models import Order

[Thu Dec 18 09:53:24 2014] [error] [client 127.0.0.1]   File "/home/nnn/webapps/ecommerce/src/orders/models.py", line 13, in <module>

[Thu Dec 18 09:53:24 2014] [error] [client 127.0.0.1]     User = get_user_model()

[Thu Dec 18 09:53:24 2014] [error] [client 127.0.0.1]   File "/home/nnn/webapps/ecommerce/lib/python2.7/django/contrib/auth/__init__.py", line 127, in get_user_model

[Thu Dec 18 09:53:24 2014] [error] [client 127.0.0.1]     user_model = get_model(app_label, model_name)

[Thu Dec 18 09:53:24 2014] [error] [client 127.0.0.1]   File "/home/nnn/webapps/ecommerce/lib/python2.7/django/db/models/loading.py", line 271, in get_model

[Thu Dec 18 09:53:24 2014] [error] [client 127.0.0.1]     self._populate()

[Thu Dec 18 09:53:24 2014] [error] [client 127.0.0.1]   File "/home/nnn/webapps/ecommerce/lib/python2.7/django/db/models/loading.py", line 78, in _populate

[Thu Dec 18 09:53:24 2014] [error] [client 127.0.0.1]     self.load_app(app_name)

[Thu Dec 18 09:53:24 2014] [error] [client 127.0.0.1]   File "/home/nnn/webapps/ecommerce/lib/python2.7/django/db/models/loading.py", line 99, in load_app

[Thu Dec 18 09:53:24 2014] [error] [client 127.0.0.1]     models = import_module('%s.models' % app_name)

[Thu Dec 18 09:53:24 2014] [error] [client 127.0.0.1]   File "/home/nnn/webapps/ecommerce/lib/python2.7/django/utils/importlib.py", line 40, in import_module

[Thu Dec 18 09:53:24 2014] [error] [client 127.0.0.1]     __import__(name)

[Thu Dec 18 09:53:24 2014] [error] [client 127.0.0.1]   File "/home/nnn/webapps/ecommerce/src/accounts/models.py", line 3, in <module>

[Thu Dec 18 09:53:24 2014] [error] [client 127.0.0.1]     from orders.models import Order

[Thu Dec 18 09:53:24 2014] [error] [client 127.0.0.1] ImportError: cannot import name Order

asked 18 Dec '14, 09:46

nathandh8
1113
accept rate: 0%

edited 18 Dec '14, 09:48


Based on the last statement in your error log you have a python search path issue. You can easily fix the path via these instructions. One helpful way to check the path is via the python shell.

permanent link

answered 18 Dec '14, 12:42

aaront ♦♦
7664
accept rate: 27%

Thanks for the quick response.

The paths seem to be added correctly in httpd.conf:

#httpd.conf
ThreadsPerChild 5
WSGIPythonPath /home/nnn/webapps/ecommerce:/home/nnn/webapps/ecommerce/src:/home/nnn/webapps/ecommerce/lib/python2.7
WSGIDaemonProcess ecommerce processes=2 threads=12 python-path=/home/nnn/webapps/ecommerce:/home/nnn/webapps/ecommerce/src:/home/nnn/webapps/ecommerce/lib/python2.7
WSGIProcessGroup ecommerce

Checking to see if they were added correctly in the shell:

[nnn@web431 src]$ python2.7 manage.py shell
Python 2.7.8 (default, Oct  7 2014, 19:28:26)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-4)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
>>> import sys
>>> print sys.path
['/home/nnn/webapps/ecommerce/src', '/home/nnn/webapps/ecommerce/lib/python2.7', '/home/nnn/lib/python2.7/pip-1.5.6-py2.7.egg', '/home/nnn/lib/python2.7', '/usr/local/lib/python27.zip', '/usr/local/lib/python2.7', '/usr/local/lib/python2.7/plat-linux2', '/usr/local/lib/python2.7/lib-tk', '/usr/local/lib/python2.7/lib-old', '/usr/local/lib/python2.7/lib-dynload', '/home/nnn/.local/lib/python2.7/site-packages', '/usr/local/lib/python2.7/site-packages', '/usr/local/lib/python2.7/site-packages/PIL']

I feel like I'm overlooking something here as all seems to be set up correctly?

Thanks!

(18 Dec '14, 15:22) nathandh8

If you 'ls' each of those paths does a module named Order exist in any of them?

(18 Dec '14, 22:22) johns

Under /home/nnn/webapps/ecommerce/src my dir structure looks like:

accounts

carts

ecommerce

orders

--models.py

----where class Order is defined

products

...

App works fine locally as well as on production but only with DEBUG set to TRUE. Don't quite understand why no error is displayed in those cases.

(19 Dec '14, 08:25) nathandh8

I notice the 'orders' directory has a lowercase O, are you using a file-system locally that is not case-sensitive? The file-system on the server is case-sensitive, so try making it a capitol O.

(19 Dec '14, 23:17) johns

Thanks for all your help. The issue is reseolved. Turned out is was related to the following lines in orders.model.py

from django.contrib.auth import get_user_model

User = get_user_model()

Don't quite understand why but I can do without the user model here so I just left it out.

(20 Dec '14, 10:09) nathandh8
Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:

×909
×30

question asked: 18 Dec '14, 09:46

question was seen: 2,792 times

last updated: 20 Dec '14, 10:10

WEBFACTION
REACH US
SUPPORT
AFFILIATE PROGRAM
LEGAL
© COPYRIGHT 2003-2019 SWARMA LIMITED - WEBFACTION IS A SERVICE OF SWARMA LIMITED
REGISTERED IN ENGLAND AND WALES 5729350 - VAT REGISTRATION NUMBER 877397162
5TH FLOOR, THE OLD VINYL FACTORY, HAYES, UB3 1HA, UNITED KINGDOM