[英]SyntaxError app_name while using Django
Hi everyone I edited this post and still got an error can someone please help. 大家好,我编辑了这篇文章,仍然出现错误,请有人帮忙。
The error is: 错误是:
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.
and the urls.py is this: 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'),
You're missing a close bracket on this line. 您在此行上缺少右括号。
Third party libraries can't cause SyntaxError
s in your code. 第三方库无法在您的代码中引起
SyntaxError
。
EDIT: You put the bracket in the wrong place. 编辑:您将支架放在错误的位置。 Refer to the docs .
请参阅文档 。
url(path, view_or_include, namespace=string)
You need to have url(r'^', include('shop.urls'), namespace='shop'),
您需要具有
url(r'^', include('shop.urls'), namespace='shop'),
Please don't edit the question to be completely different after it's been answered. 在回答完该问题后,请不要将问题完全不同。 :(
:(
from this to: 从这到:
url(r'^', include('shop.urls', namespace='shop'),
change to this: 更改为此:
url(r'^', include('shop.urls', namespace='shop')),
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.