[Answer]-About django searchname

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.

Leave a comment