jilingxf的个人博客分享 http://blog.sciencenet.cn/u/jilingxf

博文

django render 字典值设置 报TTypeError 错误

已有 1832 次阅读 2019-2-17 19:12 |个人分类:python|系统分类:科研笔记| django, render, 字典值设置, 报TTypeError, 错误

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!'}

改正之后




https://blog.sciencenet.cn/blog-853805-1162658.html

上一篇:python学习笔记(1)——创建应用
下一篇:django学习笔记(2)——使用模板
收藏 IP: 42.180.51.*| 热度|

0

该博文允许注册用户评论 请点击登录 评论 (0 个评论)

数据加载中...

Archiver|手机版|科学网 ( 京ICP备07017567号-12 )

GMT+8, 2024-4-27 07:52

Powered by ScienceNet.cn

Copyright © 2007- 中国科学报社

返回顶部