I have a django application hosted with Apache. I am using django restframework to create an API, but I am having problems with the urls. As an example, I have a URL like this:
url(r'path/to/endpoint/(?P<db_id>.+)/$', views.PathDetail.as_view())
If I try to access this URL and do not include the trailing slash, it will not match. If I add a question mark to the end as follows:
url(r'path/to/endpoint/(?P<db_id>.+)/?', views.PathDetail.as_view())
This corresponds to a slash and without it. The only problem is that if a trailing slash is used, it is now included in the db_id variable in my opinion. Therefore, when it searches for a database, the identifier does not match. I don't want to go through all my looks and remove trailing slashes from my url variables using string handling.
So my question is: what is the best way to make the URL match both the trailing slash and without it, without including the slash in the parameter that is sent to the view?
source
share