zoukankan      html  css  js  c++  java
  • Django shortcut functions

    1. django.shortcuts package提供提供帮助类和函数可以更便捷的操作MVC中的每一部分,包含:
      • render(request, template_name,[dictionary],[context_instance],[content_type],[status],[current_app],[dirs]):使用给定的context填充模板,返回HttpResponse对象,该对象的content就是模板替换后的内容.render()函数同以context_instance(RequestContext)为参调用render_to_response功能相同
        render
      • render_to_response(template_name[, dictionary][, context_instance][, content_type][, dirs]):使用给定的context填充template,并返回HttpResponse object,
        render_to_response
      • redirect(to, [permanent=False],*args, **kwargs):返回to对象的url对应的HttpResponseRedirect,默认是临时重定向,如果permanent=true则永久重定向,参数to可以是:
        • a model:这个model的get_absolute_url()函数会被调用
        • a view name:urlresolvers.reverse会被调用逆向解析view name得到url
        • 一个绝对或者相对url
      • get_object_or_404(klass, *args, **kwargs):使用给定的model manager调用get()函数,如果没得到就抛出Http404异常
      • get_list_or_404(klass, *args, **kwargs):使用给定的model manager调用filter函数返回结果转换成list,如果list为空则抛出Http404异常
  • 相关阅读:
    用kettle做ETL时设置mysql连接参数使数据写入速度加快
    infobright社区版rpm包
    mysql在大数据量下性能调优相关参数
    greenplum给某个用户赋予整个schema下所有表的权限
    Linux挂载大于2T的磁盘硬盘
    Centos 系统swap(虚拟内存)管理
    域内
    随便记录一些东西
    有关终端的一些tips
    精悍的指令
  • 原文地址:https://www.cnblogs.com/phenixyu/p/4179126.html
Copyright © 2011-2022 走看看