I have a Django template filter where I'm trying to check the request URL to see whether it includes an anchor tag or not.
For example, I want to check if the request URL is:
/mypath/mypage/my-slug/
or /mypath/mypage/my-slug/#myanchor
If it is the latter, I want to get the anchor tag ID.
Currently, the anchor tag seems to be stripped from the request information: request.path
, request.build_absolute_uri()
and so on. I can only get /mypath/mypage/my-slug/
.
The URL pattern for the page in question is:
re_path(r'^(?P<product_slug>[\w-]*)_(?P<pk>\d+)/$', self.detail_view.as_view(), name='detail')
I can see the regex looks for the line end after the last slash, which suggests the anchor is being excluded, but I can easily retrieve GET
params from the URL and I expected this to be straightforward too. It feels like I am missing something pretty obvious.