无效的语法几乎尝试了一切

invalid syntax tried almost everything

我 运行 遇到此代码的问题:

return render(request, 'count.html',{'fulltext':fulltext,'count':len(wordlist),'worddictionary':worddictionary.items("")})

CMD 告诉我第 22 行语法无效,但我找不到任何问题。

    from django.http import HttpResponse
    from django.shortcuts import render
    import operator

    def homepage(request):
        return render(request, 'home.html')

    def count(request):
        fulltext = request.GET['fulltext']

        wordlist = fulltext.split()

worddictionary = {}
for word in wordlist:
    if word in worddictionary:
        #increase
        worddictionary[word] += 1

    else:
        #add to the dictionary
        worddictionary[word] = 1
sortedwords = sorted(worddictionary.items(), key=operator.itemgetter(1), reverse=True)

return 呈现(请求,'count.html',{'fulltext':全文,'count':len(词表),'worddictionary':worddictionary.items()})

检查您的代码后,我发现您给出了字典的键值对,例如:'count':len(word list)。我建议你创建一个新变量假设 x=len(word list),然后像 'count':x 那样在字典中使用它。希望之后能得到解决

这可能是因为您的 return 语句末尾有一个额外的 '。