Home > database >  How to get the value of a form in html to django
How to get the value of a form in html to django

Time:05-19

<form action="{% url 'search' %}" method="get">
       <input  type="text" name="q" placeholder="Search Encyclopedia"> 
</form>

How can I get the value of q to views.py

def search(request):
    return render(request, "encyclopedia/search.html")

Should I make it a post request instead of a get and then take the value. Help me plz

CodePudding user response:

You use GET method, so you can use the HttpRequest.GET dictionary containing all given HTTP GET parameters.

A simple :

request.GET.get('q')

will do the job.

See https://docs.djangoproject.com/en/4.0/ref/request-response/

  • Related