[Django]-Django- empty string in url is not redirecting to the index page

6👍

Change your url path from:

path(r'^$', views.index, name='index'),

to

path('', views.index, name='index'),

Because path takes string or parts with angle bracket like <username> for dynamic parts of url. Same goes to your other url pattern definitions:

path('about/', views.about, name='about'),
path('news/', views.news, name='news'),
path('admin/', admin.site.urls),

If you are planning to use regex as part of url patterns, then please use re_path.

1👍

According to the Django Docs you must not use regular expression in path(), check it here path if you want to use regular expression, then use re_path specified here re_path.

Leave a comment