Home > Blockchain >  (urls.E004). Your URL Pattern is invalid in project level urls.py file
(urls.E004). Your URL Pattern is invalid in project level urls.py file

Time:10-14

I am newbie to Django. I am getting the below error in-spite of rightly mapping the app level urls.py file to project level urls.py. Please help.

projectlevel\urls.py

from django.contrib import admin
from django.urls import path, include

urlpatterns = [
path('admin/', admin.site.urls),
path('', include ('app_space.urls'))
]

applevel\urls.py

from importlib.resources import path
from xml.etree.ElementInclude import include
from . import views

urlpatterns = [
path('app_space/', views.home_page)
]

Error:

ERRORS:
?: (urls.E004) Your URL pattern <contextlib._GeneratorContextManager 
object at 0x0000024F8075D548> is invalid. Ensure that urlpatterns is 
a list of path() and/or re_path() instances.

CodePudding user response:

put this in MainProjectFolder(where settings.py exists)/urls:

path('', include ('app_space.urls'))

and inside your app_space/urls.py you can but a custom url like app_space/

also make sure you import include and path

from django.urls import path, include

also add this line to settings.py/INSTALLED_APP -> 'app_space',

app_space -> your app name

CodePudding user response:

You should import path and include from django.urls in your app's urls.py so:

from django.urls import path, include
from . import views
urlpatterns = [ 
    path('', views.home_page) 
]
  • Related