码迷,mamicode.com
首页 > 其他好文 > 详细

Django知识梳理

时间:2017-11-05 11:25:11      阅读:181      评论:0      收藏:0      [点我收藏+]

标签:cti   web   detail   返回   return   html   .ajax   form   admin   

请求周期:

    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)

 

Django知识梳理

标签:cti   web   detail   返回   return   html   .ajax   form   admin   

原文地址:http://www.cnblogs.com/crazytao/p/7786829.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!