0

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.

alstr
  • 1,358
  • 18
  • 34

1 Answers1

1

The section tag is not sent to the server, but interpreted by the browser : Is the anchor part of a URL being sent to a web server?

Now, if you need to the anchor ID, you will have to do so using AJAX and write your own view to receive the data.

Guillaume
  • 1,956
  • 1
  • 7
  • 9