zoukankan      html  css  js  c++  java
  • Django知识梳理

    请求周期:

        url > 路由 > 函数或类 > 返回字符串或模板语言

    Form 表单提交: 

        先处理模板语言再讲HTML发出去
          提交 > url > 函数或类中的方法  ————
              - httpResponse()     |
                render(request)     |
                redirect('/index')       |
               用户 < 返回字符串 <——

           

          注:当为redirect时,自动发起另外的请求

    ajax    

    $.ajax({
    				url:'/index',
    				data: {'k':1,'f':1},
    				type:'POST',
    				dataType:'JSON',
    				traditional:true,
    				success:function(d){
    					location.reload		#刷新
    					location.href = '某个地址'  #跳转,代替redirect
    				
    				}
    			})
    

      

    路由系统URL

        1.

          a. /index/
          b. /index/(d+)
          c. /index/(?P<nid>d+)
          d. /index/(?P<nid>d+) name = 'root'
            reverse()
            {% url 'root' 1%}
          e. /crm/ include('app01.urls')
          f. 默认值
            /index/ {'web':'root'}

            def func(request,web)
              return ...
          g.命名空间
            /admin/ include('app01.urls',namespace='author')
            /crm/ include('app01.urls',namespace='publisher')

            app01.urls
            /index/ name = detail
            reverse('author':detail)

        2.

              def func(request):
                request.POST
                request.GET
                request.FILES
                request.method
                request.path_info

                return render,HttpResponse,redirect

        3.Views


              request.body
                request.POST
                request.GET
                request.FILES
                requset.xxxx.getlist

              request.Meta
                request.method
                request.path_info
                request.COOKIES

              -请求的其他信息
                from django.core.handles.wsgi import WSGIrequest

                a = '中国'
                return HttpResponse(a)
                return render
                return redirect

                response['name'] = 'arnol' #返回到响应头
                response.set_cookie()
                return response

    装饰器    

          FBV
          CBV
          from django.utils.decorators import method_decorator
          @method_decorator(装饰函数)


          @method_decorator(装饰函数)
          def dispatch(self,request):
          return super(类名,self).dispatch(request,*args,**kwargs)

          @method_decorator(装饰函数,name='dispatch')
          class Order(Views.view)

  • 相关阅读:
    HTTP协议
    Python学习--装饰器、列表生成式、生成器、map filter、json处理
    Python学习--多线程&多进程
    Python学习--发送邮件
    Python学习--异常处理
    【第五节】【Python学习】【configparser模块】
    【第一节】【shell脚本】【文件里的内容与变量中的内容大小写替换】
    【Python】【多线程多进程】
    【Selenium学习】【拖动滚动条】
    【Python】【异常的获取与处理】
  • 原文地址:https://www.cnblogs.com/crazytao/p/7786829.html
Copyright © 2011-2022 走看看