在Django中以html格式运行Python输出

我正在做一个django项目。在应用程序的views.py中,我有一些输出要存储在字典中。 views.py看起来像这样:

from django.shortcuts import render


def allblogs(request):
    a = request.GET['a']
    b = request.GET['b']

    return render(request, 'blog/allblogs.html', {'a': a, 'b':b})

我在html文件中称这些a和b。当我只显示它们而没有这样的html代码时:

here are your {{a}} and {{b}}

然后我把它们放在无聊的白页中。但是,当我尝试用html代码调用它们时,我什么也没得到。如果我尝试这样运行它们:

{% a %}

这给了我错误:

TemplateSyntaxError at /blog/
Invalid block tag on line 98: 'a'. Did you forget to register or load this tag?
Request Method: GET
Request URL:    http://localhost:8000/blog/?the_sender=&the_amount=
Django Version: 3.0.6
Exception Type: TemplateSyntaxError
Exception Value:    
Invalid block tag on line 98: 'a'. Did you forget to register or load this tag?
Exception Location: C:\Users\Winter\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\template\base.py in invalid_block_tag, line 530
Python Executable:  C:\Users\Winter\AppData\Local\Programs\Python\Python38-32\python.exe
Python Version: 3.8.2
Python Path:    
['C:\\Users\\Winter\\Desktop\\portfolio-project',
 'C:\\Users\\Winter\\AppData\\Local\\Programs\\Python\\Python38-32\\python38.zip',
 'C:\\Users\\Winter\\AppData\\Local\\Programs\\Python\\Python38-32\\DLLs',
 'C:\\Users\\Winter\\AppData\\Local\\Programs\\Python\\Python38-32\\lib',
 'C:\\Users\\Winter\\AppData\\Local\\Programs\\Python\\Python38-32',
 'C:\\Users\\Winter\\AppData\\Local\\Programs\\Python\\Python38-32\\lib\\site-packages']
Server time:    Mon, 11 May 2020 09:25:36 +0000

谁能帮我?

评论