|||
views.py
def index(request): #return HttpResponse('hello word!') return render(request,'index.html',{'hello','hello blog key!'})
index.html
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Title</title> </head> <body> <h1>{{ hello }}</h1> </body> </html>
报类型错误
TTypeError at /index/ context must be a dict rather than set. Request Method: GET Request URL: http://localhost:8000/index/ Django Version: 2.1.7 Exception Type: TypeError Exception Value: context must be a dict rather than set. Exception Location: D:\ProgramData\Anaconda3\lib\site-packages\django\template\context.py in make_context, line 270 Python Executable: D:\ProgramData\Anaconda3\python.exe Python Version: 3.7.1 Python Path: ['D:\\code\\myblog\\myblog', 'D:\\code\\myblog\\myblog', 'D:\\ProgramData\\Anaconda3\\python37.zip', 'D:\\ProgramData\\Anaconda3\\DLLs', 'D:\\ProgramData\\Anaconda3\\lib', 'D:\\ProgramData\\Anaconda3', 'D:\\ProgramData\\Anaconda3\\lib\\site-packages', 'D:\\ProgramData\\Anaconda3\\lib\\site-packages\\win32', 'D:\\ProgramData\\Anaconda3\\lib\\site-packages\\win32\\lib', 'D:\\ProgramData\\Anaconda3\\lib\\site-packages\\Pythonwin', 'D:\\Program Files\\JetBrains\\PyCharm ' '2018.3.4\\helpers\\pycharm_matplotlib_backend'] Server time: Sun, 17 Feb 2019 10:14:39 +0000
原因:
return render(request,'index.html',{'hello','hello blog key!'})一句 {'hello','hello blog key!'}
改正之后
Archiver|手机版|科学网 ( 京ICP备07017567号-12 )
GMT+8, 2024-9-20 22:23
Powered by ScienceNet.cn
Copyright © 2007- 中国科学报社