【发布时间】:2018-07-08 12:22:41
【问题描述】:
大家好,我编辑了这篇文章,但仍然出现错误,请有人帮忙。
错误是:
File "C:\Users\myshop\myshop\urls.py", line 25, in <module>
url(r'^', include('shop.urls', namespace='shop')),
File "C:\Users\Faruq\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\urls\conf.py", line 39, in include
'Specifying a namespace in include() without providing an app_name '
django.core.exceptions.ImproperlyConfigured: Specifying a namespace in include() without providing an app_name is not supported. Set the app_name attribute in the included module, or pass a 2-tuple containing the list of patterns and app_name instead.
urls.py 是这样的:
from django.conf.urls import include, url
from django.contrib import admin
from django.conf import settings
from django.conf.urls.static import static
app_name='shop'
urlpatterns = [
url('admin/', admin.site.urls),
url(r'^', include('shop.urls', namespace='shop')),
]
if settings.DEBUG:
urlpatterns += static(settings.MEDIA_URL,
document_root=settings.MEDIA_ROOT)
【问题讨论】:
-
您在上一行缺少一个右括号/括号。投票结束这个问题。
-
我投票决定将此问题作为题外话结束,因为这是一个 OP 本可以解决的微不足道的问题。
-
欢迎来到本站!查看tour 和how-to-ask page 了解更多关于提出问题以吸引高质量答案的信息。您可以edit your question 包含更多信息。对拼写错误的近距离投票对于该网站来说是正常的——不要气馁。祝你好运!
-
好吧,错误信息告诉你该怎么做:在包含的模块中提供一个应用程序名,而不是在这个模块中(你有一个名为 shop 的应用程序并将其添加到 INSTALLED_APPS对吧?)
标签: python django syntax-error