• python之路二十一


        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)

  • 相关阅读:
    c# 方法重载
    c# propertyGrid下拉选项
    c# 枚举类型
    c# socket编程
    读书笔记之ado.net entity framework
    c# delegate的invoke和bejinInvoke的区别
    C# 读书笔记之类与结构体
    c#笔记之启动新线程
    c# listview的使用
    visual studio2013 改变匹配括号的颜色
  • 原文地址:https://www.cnblogs.com/hexinzhao/p/6253223.html
Copyright © 2020-2023  润新知