render httprequest
render
def my_view(request):# View code here...
t = loader.get_template('myapp/index.html')
c = RequestContext(request, {'foo': 'bar'})
return HttpResponse(t.render(c),content_type="application/xhtml+xml")
这就是使用 Django 模板系统的基本规则: 写模板,创建 Template 对象,创建 Context , 调用 render() 方法
redirect
return redirect('/index/')效果同样
HttpRequest
返回参数给前端 {"message": u"待办事项添加失败"}
Django之HttpRequest和HttpResponse

render¶
render_to_response
response = HttpResponse("Here's the text of the Web page."):
will create a newHttpResponseobject with HTTP code 200 (OK), and the content passed to the constructor. In general, you should only use this for really small responses (like an AJAX form return value, if its really simple - just a number or so).HttpResponseRedirect("http://example.com/"):
will create a newHttpResponseobject with HTTP code 302 (Found/Moved temporarily). This should be used only to redirect to another page-
Renders a given template with a given context dictionary and returns an HttpResponse object with that rendered text.
-
通过
httpresponse render_to_response与render返回数据给前端页面,一般返回html(模板)给前端,也可以返回其他数据
render httprequest的更多相关文章
- 前端面试angular 常问问题总结
1. angular的数据绑定采用什么机制?详述原理 angularjs的双向数据绑定,采用脏检查(dirty-checking)机制.ng只有在指定事件触发后,才进入 $digest cycle : ...
- angular的常见问题
ng-if 跟 ng-show/hide 的区别有哪些? 第一点区别是,ng-if 在后面表达式为 true 的时候才创建这个 dom 节点,ng-show 是初始时就创建了,用 display:bl ...
- Angular面试题四
二十.angular 的缺点有哪些? 1.强约束 导致学习成本较高,对前端不友好. 但遵守 AngularJS 的约定时,生产力会很高,对 Java 程序员友好. 2.不利于 SEO 因为所有内容都是 ...
- AngularJS常见面试题
本文引自:https://segmentfault.com/a/1190000005836443 问题来源:如何衡量一个人的 AngularJS 水平? ng-if 跟 ng-show/hide 的区 ...
- AngularJS 常见面试问题
ng-if 跟 ng-show/hide 的区别有哪些? 第一点区别是,ng-if 在后面表达式为 true 的时候才创建这个 dom 节点,ng-show 是初始时就创建了,用 display:bl ...
- Python Django 前后端数据交互 之 HttpRequest、HttpResponse、render、redirect
在使用三神装的时候,首先当然是得要导入它们: from django.shortcuts import HttpResponse, render, redirect 一.HttpRequest捕获 ...
- django中HttpRequest请求
视图的第一个参数必须是HttpRequest对象 在视图函数中,接收的request有如下属性: path:一个字符串,表示请求的页面的完整路径,不包含域名. method:一个字符串,表示请求使用的 ...
- $Django 虚拟环境,2.0、1.0路由层区别,Httprequest对象,视图层(fbv,cbv),文件上传
1 虚拟环境:解决问题同一台机器上可以运行不同版本的django, 1 用pychanrm创建--->files-->newproject--->选择虚拟环境 2 setting ...
- day65 request对象,以及方法,response对象,render,redirect
这里的都是我们会频繁使用到的,用得多了自然就会了,我们写项目都是少不了这些用法的,所以这就把老师的博客粘过来就好了, Request对象 官方文档 属性 所有的属性应该被认为是只读的,除非另有说明. ...
随机推荐
- hdu 4597 Play Game(记忆化搜索)
题目链接:hdu 4597 Play Game 题目大意:给出两堆牌,仅仅能从最上和最下取,然后两个人轮流取,都依照自己最优的策略.问说第一个人对多的分值. 解题思路:记忆化搜索,状态出来就很水,dp ...
- C++语言基础(15)-友元函数和友元类
一个类中可以有 public.protected.private 三种属性的成员,通过对象可以访问 public 成员,只有本类中的函数可以访问本类的 private 成员.现在,我们来介绍一种例外情 ...
- sql server 数据库基础知识(二)
CASE函数用法1:单值判断,相当于switch caseCASE expression WHEN value1 THEN returnvalue1 WHEN value2 THEN returnva ...
- iOS开发之Auto Layout入门(转)
随着iPhone6与iOS8的临近,适配的问题讲更加复杂,最近学习了一下Auto Layout的使用,与大家分享. 什么是Auto Layout? Auto Layout是iOS6发布后引入的一个全新 ...
- 【转载】利用MAVEN打包时,如何包含更多的资源文件
首先,来看下MAVENx项目标准的目录结构: 一般情况下,我们用到的资源文件(各种xml,properites,xsd文件等)都放在src/main/resources下面,利用maven打包时,ma ...
- php方法重写:Declaration of should be compatible with that
<?php// this code does trigger a strict messageerror_reporting( E_ALL | E_STRICT ); class cc exte ...
- MongoDb数据结构详解
首先,向数据库插入一条bjson数据 首先是定义文档,然后使用admin用户名密码登录,进入test数据库,向test数据库中插入此文档(“表名称和表中的记录”) 插入结果,查看mongoVUE如下图 ...
- 简简单单删除所有.svn目录
当使用了svn版本控制系统后每个目录下都会有一个.svn目录存在,开发完当交付产品或者上传到服务器时一般要把这些目录删除,其实在linux删除这些目录是很简单的,命令如下 find . -type d ...
- 我的第五个程序 java的JDBC连接mysql数据库 实现输入查询
import java.sql.*; import java.util.Scanner; public class JDBCTest { public static void main(String[ ...
- Photoshop脚本之jpg转换成eps
function saveEPS( doc, saveFile ) { var saveOptions = new EPSSaveOptions( ); saveOptions.encoding = ...