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异常
  • 相关阅读:
    NOIP2009 pj
    数星星(POJ2352 star)
    洛谷 p3372 模板-线段树 1
    Luogu P1198 [JSOI2008]最大数 线段树
    Bestcoder#92&HDU 6017 T3 Girl loves 233 DP
    NOIP2008pj & luoguP1058 立体图 模拟
    NOIP2003TG 加分二叉树 区间DP
    Redis Jedis lua脚本
    Mac Ideal 常用快捷键
    Mysql慢查询explain
  • 原文地址:https://www.cnblogs.com/phenixyu/p/4179126.html
Copyright © 2011-2022 走看看