-3

在下面的代码中,我试图检查发布的内容是否有任何关键字为“whatis”或“what”,一切正常,但是当我输入 if 语句时,它显示语法错误

def addsearch(request):
    addsearch = request.POST.get('searchcontent')
    wordlist = re.sub("[^\w]", " ", addsearch).split()


    s = ''.join(wordlist)
    question = re.findall('whatis', s)[0]

    q = ''.join(wordlist)
    question1 = re.findall('what', q)[0]

    q1 = "what" , q2 ="whatis"
    if question == q2 or question1 == q1
        abc = "this is a question"

    return render(request, 'searchme.html', {"addsearch": addsearch, "splitcontent":wordlist,"question":question,"abc":abc})
4

2 回答 2

2

您的代码中有 2 个错误。

首先是变量声明,改变这个:

q1 = "what" , q2 = "whatis"

对此:

q1 = "what"
q2 = "whatis"

第二个是你需要:在最后写的 if 语句:

if question == q2 or question1 == q1:
        abc = "this is a question"
于 2019-05-16T17:21:33.420 回答
1

您有语法错误,因为您没有在 if 语句中包含冒号。

改变:

if question == q2 or question1 == q1
            abc = "this is a question"

对此:

if question == q2 or question1 == q1:
            abc = "this is a question"
于 2019-05-16T17:21:43.573 回答