[英]SyntaxError app_name while using Django
大家好,我编辑了这篇文章,仍然出现错误,请有人帮忙。
错误是:
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)
url(r'^', include('shop.urls', namespace='shop'),
您在此行上缺少右括号。
第三方库无法在您的代码中引起SyntaxError
。
编辑:您将支架放在错误的位置。 请参阅文档 。
url(path, view_or_include, namespace=string)
您需要具有url(r'^', include('shop.urls'), namespace='shop'),
在回答完该问题后,请不要将问题完全不同。 :(
从这到:
url(r'^', include('shop.urls', namespace='shop'),
更改为此:
url(r'^', include('shop.urls', namespace='shop')),
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.