Answer the question
In order to leave comments, you need to log in
Why is the query condition written in quotation marks?
I'm learning django from a book, I got to the site search.
Can you explain why (if 'query' in request.GET) query is written in quotes?
#forms.py
class SearchForm(forms.Form):
query = forms.CharField()
#views.py
def post_search(request):
form = SearchForm()
query = None
results = []
if 'query' in request.GET:
form = SearchForm(request.GET)
if form.is_valid():
query = form.cleaned_data['query']
results = Post.objects.annotate(search=SearchForm('title', 'body')).filter(search=query)
return render(requets, 'blog/post/search.html', {'form': form,
'query': query,
'results': results})
Answer the question
In order to leave comments, you need to log in
because type == str
If it was not passed in the parameters, there is no need to load the server
Learn python first, and then already Django
request.GET is a dictionary and so it is searched in it for an entry with such a key
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question