python|python django常用的函数

python django常用的函数
1)render(): 渲染页面

from django.shortcuts import renderdef index(request): return render(request, 'TestModel/index.html')

2)JsonResponse(): 渲染json数据
from django.http import JsonResponsedef upload(request): return JsonResponse({'result':200, 'success':True})

【python|python django常用的函数】3)HttpResponse:
from django.http import HttpResponse# 下载图片 def download(request, filename): file = open('%s' %filename).read() return HttpResponse(file)

    推荐阅读