pythondjangodjango-urlsdjango-2.0

URL patterns in Django 2


I just have started my first project by using Django 2.0 in which I need to define a URL in a way as: http://localhost:8000/navigator?search_term=arrow

But I couldn't know how to define a string parameter for a URL in Django 2.0

Here's what I have tried:

From ulrs.py:

from Django.URLs import path from. import views

urlpatterns = [
    path('navigator/<str:search_term>', views.GhNavigator, name='navigator'),

]

Any help?


Solution

  • There is no need to define query params in URL. Below url is enough to work.

    path('navigator/', views.GhNavigator, name='navigator')
    

    Let you called URL http://localhost:8000/navigator/?search_term=arrow then you can get search_term by request.GET.get('search_term').