简体   繁体   中英

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:

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.

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'),

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')),

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM