[PYTHON] Get parameter values ​​in Django templates

Thing you want to do

https://example.com/?year=2021&month=1

I want to take the values ​​of the parameters year and month on the template side when accessing with.

Solutions

When taking the value of year {{ request.GET.year }} Obtained at.

To take the value of month {{ request.GET.month }} Obtained at.

Remarks

{% for key, value in request.GET.items %}
    {{ key }} = {{ value }}
{% endfor %}

You can take it even if you turn it like this.

year = 2021 month = 1

Recommended Posts

Get parameter values ​​in Django templates
PHP var_dump in Django templates
Handle constants in Django templates
Transfer parameter values in Python
Get the query string (query string) in Django
Get the client's IP address in Django
Get query parameters for GET requests in Django
Models in Django
Forms in Django
How to get multiple model objects randomly in Django
Get environment variables in Python, otherwise set default values
Model changes in Django
Swapping values in Python
Get date in Python
How to get all the keys and values in the dictionary
Get YouTube Comments in Python
Performance optimization in Django 3.xx
Implement follow functionality in Django
Get started with Django! ~ Tutorial ⑤ ~
Use parameter store in Python
Rename table columns in Django3
Output table structure in Django
Get started with Django! ~ Tutorial ④ ~
Get started with Django! ~ Tutorial ⑥ ~
Get Terminal size in Python
Explicitly get EOF in python
(Note) Django in Vagrant environment
Get Evernote notes in Python
Show Django ManyToManyField in Template
Get Japanese synonyms in Python
If you get Error: That port is already in use. In Django
How to get all the possible values in a regular expression
python> Display 3 decimals in ".3f, .3f, .3f" format / Get 3 coordinate values in the range [-1: 1]
[python] Get the rank of the values in List in ascending / descending order