zoukankan      html  css  js  c++  java
  • Django的快捷功能

    Django shortcut functions?:
    
    Django的快捷功能
    
    包 django.shortcuts 收集辅助函数和类,跨越MVC的多个层次,换句话说,
    
    那些函数/类 介绍控制耦合用于方便起见
    
    render()
    render(request, template_name, context=None, content_type=None, status=None, using=None)[source]
    
       return render(req,'cmdb/modifyBtn.html',{'info':info})
       
       结合给定的模板使用一个给定的上下文字典,返回一个 HttpResponse object with that rendered text
       
     Django 不提供一个快捷功能函数 返回一个TemplateResponse,因为TemplateResponse的构造提供相同的便利
     
     Required arguments
     
     需要的参数
     
     request
     
     请求对象用于生成这个响应
     
     template_name
     
     模板的全名 来使用或者模板名字的sequence 如果一个sequence给定,
     
     第一个模板被使用
     
     
     额外的参数:
     
     context
     
     字典的值 增加到模板上下文。默认情况下,这是一个空的字典。
     
     如果字典里的值是可调用的,视图会调用它在呈现模板前
     
     例子:
     
     下面面的例子 展现模板 myapp/index.html 使用MIME类型
     
        return render(req,'cmdb/modifyBtn.html',{'info':info})
    	
    	
    def year_archive(request, aaaa):
         print '-------------------------'
         print aaaa
         print '-------------------------'
         #response = "You're looking at first  the results of question %s."
         #return HttpResponse(response % aaaa)
         #return redirect('https://www.sogou.com/')
         return render(request, 'cmdb/year_archive.html', {
            'foo': aaaa,
        })
    	
    node2:/django/mysite/news/templates/cmdb#vim year_archive.html
    
    <label class="condition">地址</label><input type="text" name="ip" class="equipment_sz" value="{{foo}}">
    
    http://192.168.137.3:9000/articles/9999/
    
    render_to_response()¶
    
    render_to_response(template_name, context=None, content_type=None, status=None, using=None)[source]¶
    
    这个函数在render()引起之前,工作类似   已经被弃用 
    
    redirect()¶
    
    redirect(to, permanent=False, *args, **kwargs)[source]¶
    
    返回HttpResponseRedirect 到一个合适的URL 对于传递的参数
    
    参数是:
    
    1.一个模型:模型的get_absolute_url() function will be called.
    
    2.	

  • 相关阅读:
    数30的小程序
    convert curl command into java HttpGet
    优秀技术文章转载备份 --- 变速原理
    用 c 调用 win-api 实现自动点击c# winform 程序 的按钮
    win 10 安装 glew 方法
    《想到什么更新什么系列》processing 性能优化
    processing 根据物体移动方向改变朝向
    openFrameworks 无法生成exe已经找不到dll的解决方案
    UE4 无法打开源文件“file_name.generated.h”(Cannot open source file name.generated.h)
    UE4 重新编译老版本的插件
  • 原文地址:https://www.cnblogs.com/hzcya1995/p/13349280.html
Copyright © 2011-2022 走看看