python django常用的函数

web开发

浏览数:344

2019-8-25

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)

作者:廖马儿