Client submits post to django with 403 error csrf

      When using a client like django's server to submit a post request. Will get 403, permission exception.

 

Because django has verification for the submitted advice. So it will be.

Solution http://stackoverflow.com/questions/6800894/django-returns-403-error-when-sending-a-post-request

 

import module

from django.views.decorators.csrf import csrf_exempt

Add a decorator in front of the function

@csrf_exempt

 

 

[python]  view plain copy  
 
  1. #If the post submitted by the client does not add this paragraph, 403error will appear  
  2. @csrf_exempt  
  3. def api_blogs(request):  
  4.     if request.method == 'POST'and request.POST['page']:   
  5.         int_page = int(request.POST['page'])  
  6.     else:  
  7.         int_page = 1  
  8.   
  9.     blogs = dbBlog.objects.order_by('-created_date').all()  
  10.   
  11.     page_size = 10  
  12.     after_range_num = 5  
  13.     before_range_num = 6  
  14.   
  15.     paginator = Paginator(blogs, page_size)  
  16.   
  17.     try:  
  18.         blogs = paginator.page(int_page)  
  19.     except(EmptyPage, InvalidPage, PageNotAnInteger):  
  20.         blogs = paginator.page(1)  
  21.   
  22.     try:  
  23.         return_json = serializers.serialize('json',blogs.object_list)  
  24.     except :  
  25.         return_json = {  
  26.             'status'1,  
  27.             'msg' 'Extract blog exception'   
  28.         }  
  29.   
  30.     return HttpResponse(  
  31.         return_json  
  32.     )  

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326986889&siteId=291194637