python django常用的函数

python django常用的函数

1)render(): 渲染页面

from django.shortcuts import render

def index(request):
    return render(request, 'TestModel/index.html')

2)JsonResponse(): 渲染json数据

from django.http import JsonResponse

def upload(request):
    return JsonResponse({'result':200, 'success':True})

3)HttpResponse:

from django.http import HttpResponse

# 下载图片
def download(request, filename):
    file = open('%s' %filename).read()
    return HttpResponse(file)

你可能感兴趣的:(python django常用的函数)