request.path not showing query string django templates

0 votes
asked Apr 10, 2017 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

having query string

the HTML output is

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

1 Answer

0 votes
answered Apr 10, 2017 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