I have a django app. In the app I have a url that looks like:-
path('url/', views.appmain, name="main")
The problem is that the trailing slash is required. I want to make the slash optional and the url accessible both with or without the slash.
I checked APPEND_SLASH
but it doesn't work. What's the solution for it.
You can use re_path
instead of path
for use regular expression in your url pattern. use ?
sign in your url like this:
from django.urls import re_path
re_path(r'url/?$', views.appmain, name="main")
Note: question mark matches zero or one /
in the url. it accepts both domain.com/url
and domain.com/url/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With