I'm trying to dynamically access GET parameters in Django template, but it's not working.
URL: ?id=1&name=John
I've tried something like this:
{% for r in request.GET %}
    {% if request.GET.r %}
        {{r}} = {{request.GET.r}}
    {% endif %}
{% endfor %}
The problem is that even if the parameters are set, nothing is returned in the template.
It works though if I do request.GET.id or request.GET.name
Any ideas?
As request.GET is a dictionary, you should use request.GET.items in the loop (docs).
{% for key, value in request.GET.items %}
    {{key}} = {{value}}
{% endfor %}
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With