Django NameError [应用程序名称] 未定义
尝试使用 django-grappelli 作为我的管理主题,安装非常具有挑战性。在我的 urls.py 中遇到以下内容:
NameError .. name 'grappelli' is not defined
在 Installed grappelli with pip行上抛出错误
(r'^grappelli/', include(grappelli.urls))
,并且 grappelli 位于我的sites-packages 目录中。添加到我的 INSTALLED_APPS
中,运行syncdb,尝试将 grappelli 添加到我的 pythonpath 中,但没有成功。如果我在 urls.py 中导入 grappelli,错误将更改为 AttributeError - 'module' has no attribute 'urls'
非常感谢建议或任何类型的帮助。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
该行应为:
include
要么采用 urls 模块的路径,要么它可以是返回 url 模式的 python 对象http://docs.djangoproject.com/en/dev/topics/http/urls/# include
因此,你的两个选项要么是上面的行(url 的路径),要么
至于错误,它是 Python 中最直接的调试错误之一:
grappelli
is not Defined,如..尚未定义。想象一下在 shell 中:
Line should read:
include
either takes a path to a urls module OR it can be a python object that returns the url patternshttp://docs.djangoproject.com/en/dev/topics/http/urls/#include
So your two options are either the line above (path to urls) or
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:
我意识到这已经有一年多了,但当我遇到同样的问题时,它是谷歌上的最佳结果之一。
而不是从 Gratelli.urls 导入 urlpatterns。
您还可以将 include() 语句更改为,
这也让我有点困惑,直到我注意到需要在 include 语句中引用 package.urls。
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
to
This threw me off for a bit as well until I noticed the need for quoting the package.urls in the include statement.
您可能需要在 urls.py 中导入以下内容:
You might want to import the following in urls.py:
当声明你的路线时,你忘记引用一个表达式。
将
grappelli.urls
替换为'grappelli.urls'
以使其正常工作!正确的语法是:
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: