[英]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.