request.path not showing query string django templates

0 votes
98 views
asked Apr 10 by anonymous

In my django templates {{request.path}} not showing complete url (url with query string paramaters)

i have a href
<a href="/login/?next={{ request.path }}">Login</a>

on a url

http://somedomain.com/result/?somequery=somevalue&otherquery=othervalue

having query string

the HTML output is

http://somedomain.com/login/?next=/result/

It is missing query string parameters, the expected url should be with querystring parameters as

http://somedomain.com/login/?next=/result/?somequery=somevalue&otherquery=othervalue

1 Answer

0 votes
answered Apr 10 by anonymous

First off nicely explained question.

{{request.path}} will return full path of requested page without domain or http stuff

{{ request.get_full_path }} return what {{request.path}} returns plus querystring if present.

so you can use

<a href="/login/?next={{ request.get_full_path|urlencode }}">Login</a>

It's alway a good idea to use urlencode when dealing with query string

...