1
If ('q' in request.POST) and request.POST['q'].strip()
evaluates to False
, query_string
variable stays undefined.
One way to fix the problem is to initialize the variable before the if
statement:
@login_required
def search_name(request):
form = ArticleForm(request.POST)
query_string = None
if ('q' in request.POST) and request.POST['q'].strip():
...
Hope that helps.
Source:stackexchange.com