å 为djangoé对æ交ç请æï¼ææ ¡éªãæ以ä¼å¦æ¤ã
导å
¥æ¨¡å
from django.views.decorators.csrf import csrf_exempt
å¨å½æ°åé¢æ·»å 修饰å¨
@csrf_exempt
[python] view plain copy
#客æ·ç«¯æ交çpostå¦æä¸å è¿æ®µï¼ä¼åºç°403error
@csrf_exempt
def api_blogs(request):
if request.method == 'POST' and request.POST['page']:
int_page = int(request.POST['page'])
else:
int_page = 1
blogs = dbBlog.objects.order_by('-created_date').all()
page_size = 10
after_range_num = 5
before_range_num = 6
paginator = Paginator(blogs, page_size)
try:
blogs = paginator.page(int_page)
except(EmptyPage, InvalidPage, PageNotAnInteger):
blogs = paginator.page(1)
try:
return_json = serializers.serialize('json',blogs.object_list)
except :
return_json = {
'status': 1,
'msg' 'æåblogå¼å¸¸'
}
return HttpResponse(
return_json
)
温馨提示:答案为网友推荐,仅供参考