I am currently trying to develop a rather simple application using django, but I am stuck pretty much at the beginning: My project is named "kundencenter", my app is "customermgr".
Both, the project and the app have a urls.py, the project's urls.py includes the app's:
from django.conf.urls import patterns, include, url
# Uncomment the next two lines to enable the admin:
from django.contrib import admin
admin.autodiscover()
urlpatterns = patterns('',
url(r'^customer/', include('kundencenter.customermgr.urls')),
url(r'^admin/doc/', include('django.contrib.admindocs.urls')),
url(r'^admin/', include(admin.site.urls)),
)
But when I now try to access customer/, I am presented with an ImportError:
Django Version: 1.4
Exception Type: ImportError
Exception Value:
No module named customermgr.urls
Exception Location: /usr/local/lib/python2.7/dist-packages/django/utils/importlib.py in import_module, line 35
Python Executable: /usr/bin/python
Python Version: 2.7.1
Python Path:
['/usr/lib/python2.7',
'/usr/lib/python2.7/plat-linux2',
'/usr/lib/python2.7/lib-tk',
'/usr/lib/python2.7/lib-old',
'/usr/lib/python2.7/lib-dynload',
'/usr/local/lib/python2.7/dist-packages',
'/usr/lib/python2.7/dist-packages',
'/usr/lib/python2.7/dist-packages/PIL',
'/usr/lib/python2.7/dist-packages/gtk-2.0',
'/usr/lib/pymodules/python2.7',
'.',
'/var/www/kundencenter',
'/var/www']
As you can see, I've already gone nuts with the PYTHONPATH, but to no avail. As you might have guessed, the project is located in /var/www/kundencenter. I have also already checked that the __init__.py files were created, which they were (they are empty). The error appears when I run manage.py runserver and also using Apache with mod_wsgi.
I am pretty much at the end of my wisdom. Does anybody have any idea how I could get rid of this error?
Have you tried without the project name ?
url(r'^customer/', include('customermgr.urls')),
instead of
url(r'^customer/', include('kundencenter.customermgr.urls')),
By the way, if it's not the case, import your models (or everything else) with the shortest path possible. If you import models inside the same app, juste use "from models import X,Y,Z".
If you have to import models, functions, classes, whatever, from any other app, use "from my_other_app.models import X,Y,Z", but never include your project name.
If someday, you want to recycle your app for another django project, it will spare you some pain :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With