Get request with query parameters look like this:
http://localhost:8000/?param=value1
Get request with URL parameters look like this:
http://localhost:8000/value1/
...
<a href="/?param=value1">Value 1</a>
<a href="/?param=value2">Value 2</a>
...
from django.views.generic import TemplateView
class index(TemplateView):
template_name = 'polls/index.html'
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
param = self.request.GET.get('param')
print(param)
context['param'] = param
context['message'] = "Some message from the server!"
return context
Tested with Django 4.2
09 Sept. 2024
|
Last Updated: 02 Dec. 2025
|
jaimedcsilva Related