John
John

Reputation: 4038

How to get full current url (include #anchor) in jinja2

My url is https://example.com/#3454

I tried request.url, but it returns only https://example.com/

How can I get full https://example.com/#3454 url (include anchor)

Upvotes: 2

Views: 866

Answers (1)

Mickster
Mickster

Reputation: 309

In Flask/ Jinja2 I'm using:

In the target page (e.g. home) I set an anchor by adding an id to a div:

<div id="3454"></div>

In the link towards the anchor I specify the url_for page and set the target using the _anchor parameter.

<a href="{{ url_for('page.home',_anchor='3454') }}">Test</a>

Jinja then generates a .../#3454 hyperlink for me.

My package verions:

Flask==1.1.2
jinja2==2.11.1

Upvotes: 1

Related Questions