尝试将 django-grappelli 用于我的管理主题,安装非常具有挑战性。在我的 urls.py 中遇到以下内容:
NameError .. name 'grappelli' is not defined
在线上抛出错误
(r'^grappelli/', include(grappelli.urls))
用 pip 安装了 grappelli,grappelli 在我的 sites-packages 目录中。添加到我的 INSTALLED_APPS
,运行 syncdb,尝试将 grappelli 添加到我的 pythonpath,但没有成功。如果我在 urls.py 中导入 grappelli,错误会变为 AttributeError - 'module' has no attribute 'urls'
非常感谢您的建议或任何形式的帮助。
最佳答案
行应为:
(r'^grappelli/', include('grappelli.urls'))
include
要么接受一个 urls 模块的路径,要么它可以是一个返回 url 模式的 python 对象
http://docs.djangoproject.com/en/dev/topics/http/urls/#include
所以您的两个选项是上面的行(url 路径)或
from grappelli.urls import urlpatterns as grappelli_urls
(r'^grappelli/', include(grappelli_urls)),
至于错误,它是 Python 中最直接的调试错误之一:grappelli
is not defined,如..它尚未定义。
想象一下在外壳中:
>>> print grappelli
exception: variable undefined
>>> grappelli = 'hello' # we just defined grappelli
>>> print grappelli
'hello'
关于python - Django NameError [应用程序名称] 未定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4980297/