在下面的代码中,我正在尝试检查发布的内容是否具有任何关键字“ 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})
答案 0 :(得分:2)
您的代码中有2个错误。
第一个是变量声明,更改如下:
q1 = "what" , q2 = "whatis"
对此:
q1 = "what"
q2 = "whatis"
第二个是if语句,您需要在末尾写:
:
if question == q2 or question1 == q1:
abc = "this is a question"
答案 1 :(得分:1)
您遇到语法错误,因为您的if语句中未包含冒号。
更改:
if question == q2 or question1 == q1
abc = "this is a question"
对此:
if question == q2 or question1 == q1:
abc = "this is a question"