Trying to use django-grappelli for my admin theme, install has been surprisingly challenging. Running into the following in my urls.py:
NameError .. name 'grappelli' is not defined
The error is thrown on the line
(r'^grappelli/', include(grappelli.urls))
Installed grappelli with pip, and grappelli is in my sites-packages directory. Added to my INSTALLED_APPS
, ran syncdb, tried adding grappelli to my pythonpath, but no luck. If I import grappelli in urls.py the error changes to an AttributeError - 'module' has no attribute 'urls'
Suggestions or any kind of help is highly appreciated.
Line should read:
(r'^grappelli/', include('grappelli.urls'))
include
either takes a path to a urls module OR it can be a python object that returns the url patterns
http://docs.djangoproject.com/en/dev/topics/http/urls/#include
So your two options are either the line above (path to urls) or
from grappelli.urls import urlpatterns as grappelli_urls
(r'^grappelli/', include(grappelli_urls)),
As for the error, it's one of the most straight forward errors in Python to debug: grappelli
is not defined, as in.. it hasn't been defined.
Imagine being in the shell:
>>> print grappelli
exception: variable undefined
>>> grappelli = 'hello' # we just defined grappelli
>>> print grappelli
'hello'
I realize this is over a year old, but it was one of the top results on Google when I was having this same problem.
Rather than importing urlpatterns from grapelli.urls, you can also change the include() statement
(r'^grappelli/', include(grappelli.urls))
to
(r'^grappelli/', include('grappelli.urls'))
This threw me off for a bit as well until I noticed the need for quoting the package.urls in the include statement.
You might want to import the following in urls.py:
from django.conf.urls import include
When declaring your routes, you forgot to quote an expression.
Replace grappelli.urls
by 'grappelli.urls'
to make it work!
The correct syntax would then be:
(r'^grappelli/', include('grappelli.urls'))
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