gpt4 book ai didi

python - 使用Django时出现SyntaxError app_name

转载 作者:行者123 更新时间:2023-12-03 08:27:11 24 4
gpt4 key购买 nike

大家好,我编辑了这篇文章,但仍然出现错误,请有人帮忙。

错误是:

  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

编辑:您将支架放在错误的位置。请引用 the docs
url(path, view_or_include, namespace=string)
您需要 url(r'^', include('shop.urls'), namespace='shop'),
回答完毕后,请勿将问题完全编辑。 :(

关于python - 使用Django时出现SyntaxError app_name,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48507481/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com