Regular Expressions not resolved after using re_path in django urls

I have a problem with Django urls:
main urls.py

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

urlpatterns = [
    path('admin/', admin.site.urls),
    re_path(r'^', include('tutorials.urls')),
]

tutorials/urls.py

from django.urls import re_path
from tutorials import views

urlpatterns = [
    re_path(r'^api/tutorials$', views.tutorial_list),
    re_path(r'^api/tutorials/(?P<pk>[0-9]+)$', views.tutorial_detail),
    re_path(r'^api/tutorials/published$', views.tutorial_list_published)
]

when i go to check API via browser after python manage.py runserver i get: enter image description here

Looks like regular expressions are not resolved? Any ideas?

You asked the "http://127.0.0.1:8080/api" URL. Your urlpatterns does not contains any path which could match with this url. I don't know where you want to go with this url, but if you add

path('api', views.tutorial_list),

In your urlpatterns list, you will go to tutorial_list view for example.

You don't need to use re_path for path without regular expression. just use path function.

Back to Top