0
<form action="{% url 'search' %}" method="get">
       <input class="search" 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

1 Answer 1

1

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/

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.