GET (URL Parameters)

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/

 

from django.urls import path
from .views import *

urlpatterns = [
    path("<str:param>/", index.as_view(), name="index"),
]

 

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 = kwargs.get('param')

        print(param)

        context['param'] = param
        context['message'] = "Some message from the server!"

        return context

 

...

<a href="{% url 'index' 'value1' %}"> Value 1 </a>
<a href="{% url 'index' 'value2' %}"> Value 2 </a>

...

Tested with Django 4.2



22 May 2025 | Last Updated: 02 Dec. 2025 | jaimedcsilva

Related
  • GET (Query Parameters)
  • GET (URL Parameters)
  • GET with AJAX (Fetch)
  • POST
  • POST with AJAX (Fetch)

  • Buy Me a Coffee