URL
        - 两个
    Views
        - 请求的其他信息
        from django.core.handlers.wsgi import WSGIRequest
        request.environ
        request.environ['HTTP_USER_AGENT']
        - 装饰器
            FBV:
                def auth(func):
                    def inner(reqeust,*args,**kwargs):
                        v = reqeust.COOKIES.get('username111')
                        if not v:
                            return redirect('/login/')
                        return func(reqeust, *args,**kwargs)
                    return inner
        
            CBV:
                from django import views
                from django.utils.decorators import method_decorator

                @method_decorator(auth,name='dispatch')
                class Order(views.View):

                    # @method_decorator(auth)
                    # def dispatch(self, request, *args, **kwargs):
                    #     return super(Order,self).dispatch(request, *args, **kwargs)

                    # @method_decorator(auth)
                    def get(self,reqeust):
                        v = reqeust.COOKIES.get('username111')
                        return render(reqeust,'index.html',{'current_user': v})

                    def post(self,reqeust):
                        v = reqeust.COOKIES.get('username111')
                        return render(reqeust,'index.html',{'current_user': v})
    Templates
        - 母版...html
            extends
            include
        - 自定义函数
            simple_tag
                a. app下创建templatetags目录
                b. 任意xxoo.py文件
                c. 创建template对象 register
                d.
                    @register.simple_tag
                    def func(a1,a2,a3....)
                        return "asdfasd"
                e. settings中注册APP
                f. 顶部 {% load xxoo %}
                g. {% 函数名 arg1 arg2 %}
                缺点:
                    不能作为if条件
                优点:
                    参数任意
            filter
                a. app下创建templatetags目录
                b. 任意xxoo.py文件
                c. 创建template对象 register
                d.
                    @register.filter
                    def func(a1,a2)
                        return "asdfasd"
                e. settings中注册APP
                f. 顶部 {% load xxoo %}
                g. {{ 参数1|函数名:"参数二,参数三" }} {{ 参数1|函数名:数字 }}
                缺点:
                    最多两个参数,不能加空格
                优点:
                    能作为if条件
            
    分页(自定义的分页)
        
        XSS:
            {{ page_str|safe }}
            
            mark_safe(page_str)

python之路二十一的更多相关文章

  1. python之路二十

    一, $.ajax,这个是JQuery对ajax封装的最基础步,通过使用这个函数可以完成异步通讯的所有功能.也就是说什么情况下我们都可以通过此方法进行异步刷新的操作.但是它的参数较多,有的时候可能会麻 ...

  2. Python学习(二十一) —— 前端之JavaScript

    转载自http://www.cnblogs.com/liwenzhou/p/8004649.html 一.JavaScript概述 1.JavaScript的历史 1992年Nombas开发出C-mi ...

  3. Python之路(第二十一篇) re模块

    一.re模块 正则表达式本身是一种小型的.高度专业化的编程语言,正则表达式就是字符串的匹配规则,在多数编程语言里都有相应的支持,python里对应的模块是re,正则表达式模式被编译成一系列的字节码,然 ...

  4. Python之路(第十一篇)装饰器

    一.什么是装饰器? 装饰器他人的器具,本身可以是任意可调用对象,被装饰者也可以是任意可调用对象. 强调装饰器的原则:1 不修改被装饰对象的源代码 2 不修改被装饰对象的调用方式 装饰器的目标:在遵循1 ...

  5. Py修行路 python基础 (二十一)logging日志模块 json序列化 正则表达式(re)

    一.日志模块 两种配置方式:1.config函数 2.logger #1.config函数 不能输出到屏幕 #2.logger对象 (获取别人的信息,需要两个数据流:文件流和屏幕流需要将数据从两个数据 ...

  6. python之路二

    .pyc是个什么鬼? 1. Python是一门解释型语言? 我初学Python时,听到的关于Python的第一句话就是,Python是一门解释性语言,我就这样一直相信下去,直到发现了*.pyc文件的存 ...

  7. Python之路第十一天,高级(3)-Python操作 Memcached、Redis

    Memcached Memcached 是一个高性能的分布式内存对象缓存系统,用于动态Web应用以减轻数据库负载.它通过在内存中缓存数据和对象来减少读取数据库的次数,从而提高动态.数据库驱动网站的速度 ...

  8. python之路(二)-collections系列

    collections提供了一些比较方便的方法,使用时需要先导入模块 导入模块: import collections 1. 计数器Counter 统计参数中出现的次数,以字典的方式返回结果,参数可以 ...

  9. Python学习札记(二十一) 函数式编程2 map/reduce

    参考:map/reduce Note 1.map():map()函数接收两个参数,一个是函数,一个是Iterable.map将传入的函数依次作用到序列的每个元素,并把结果作为新的Iterator返回. ...

随机推荐

  1. C#文件帮助类FoderHelper

    using System; using System.Data; using System.Configuration; using System.Linq; using System.Web; us ...

  2. sql 代码笔记

    1. if() 函数 推荐一个学习MySQL的网站  Study MySql

  3. UIDynamic--动力元素行为:UIDynamicItemBehavior

    属性分析: @property (nonatomic, readonly, copy) NSArray* items; @property (readwrite, nonatomic) CGFloat ...

  4. javascipt的【函数表达式】

    函数表达式 在编程时,我们可以看到不管是什么类库,jquery也好,zepto也好,都会用到大量的命名函数和匿名函数表达式,本节点就是为了弄懂为何会有这些函数表达式,以及在什么情况下会使用到这些表达式 ...

  5. Linux哲学思想--基本法则

    1.一切皆文件: 2.单一目的的小程序: 3.组合小程序完成复杂任务: 4.文本文件保存配置信息: 5.尽量避免捕获用户接口: 6.提供机制,而非策略. 自从Linux一诞生就注定了其成为经典的命运. ...

  6. Beta阶段第六次Scrum Meeting

    情况简述 BETA阶段第六次Scrum Meeting 敏捷开发起始时间 2016/12/16 00:00 敏捷开发终止时间 2016/12/17 00:00 会议基本内容摘要 平稳推进 参与讨论人员 ...

  7. mysql 远程连接数据库的二种方法

    http://blog.csdn.net/freecodetor/article/details/5799550 一.连接远程数据库: 1.显示密码 如:MySQL 连接远程数据库(192.168.5 ...

  8. TCP的三次握手(建立连接)和四次挥手(关闭连接)

    参照: http://course.ccniit.com/CSTD/Linux/reference/files/018.PDF http://hi.baidu.com/raycomer/item/94 ...

  9. java 反射

    com.my.Ob; @Table(name="ob") class Ob{ @Id private Integer id; @Column(name="name1&qu ...

  10. 静态方法中不能new内部类的实例对象的总结

    class Test{ public void main(String[] args){ A testA=new A(); //这里会出现问题 new Thread(new Runnable(){ p ...