3

Is it possible to get an specific parameter in a url and use it in a template ?

`{{ request.path }}

It gets the whole url, i need only the 'pk' parameter, to make a link to another page.

Thanks.

Goun2
  • 417
  • 1
  • 11
  • 22
  • 2
    You can pass the parameter to the view and make it a context variable. That will allow you to use it in your template. – jape Nov 25 '16 at 04:37
  • 3
    Is this something you really need to do in the template? Presumably you've used the parameter for something in your view so why not use that? – Sayse Nov 25 '16 at 07:39

1 Answers1

9

I did some experiments and find that this may help:

{{ request.resolver_match.kwargs.pk }}

For more info you can check this.

shellbye
  • 4,620
  • 4
  • 32
  • 44