首页 > 其他 > 详细

Django使用笔记

时间:2018-11-28 20:27:25      阅读:133      评论:0      收藏:0      [点我收藏+]
1.视图返回HTTP内容

#直接返回文字内容
return HttpResponse(‘Hello Word! You\‘re at the polls index‘)

#使用模版返回内容
template = loader.get_template(‘polls/index.html‘)
return HttpResponse(template.render(context,request))

#简化的使用模版返回内容
return render(request,‘polls/index.html‘,context)

2.urls.py文件配置内容

#?P<question_id>表示将捕获的值赋一个变量名,可以直接通过变量名引用他,而不用管位置
url(r‘^(?P<question_id>[0-9]+)/results/$‘,views.results,name=‘results‘),

Django使用笔记

原文:http://blog.51cto.com/keefe/2323415

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!