简体   繁体   中英

ImproperlyConfigured urls.py in Django

I have the following error and I can't figure out what to change in my urls.py to fix this:

django.core.exceptions.ImproperlyConfigured: The included URLconf 'MLtest.urls' does not appear to have any patterns in it. If you see valid patterns in the file then the issue is probably caused by a circular import.

Here's what my urls.py looks like:

from django.contrib import admin
from django.urls import path, include
from MLT import views
import debug_toolbar

urlpatterns = [
    path('admin/', admin.site.urls),
    path('', views.thankYou),
    path(r'^__debug__', include(debug_toolbar.urls)),
]

views.py:

from django.shortcuts import render
from django.template import RequestContext
from django.utils.translation import gettext as _

def thankYou(request):
    text = _("this is some random text")
    return render(request, 'thank_you.html', {'text': text})

You mustn't use regex with path() function.Your last url path(r'^__debug__', include(debug_toolbar.urls)) contains regex expression. You can see url definitions here

correct your url as below:

urlpatterns = [
    path('admin/', admin.site.urls),
    path('', views.thankYou),
    path('__debug__/', include(debug_toolbar.urls)),
]

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