Python - Django生活不易 我用pythonPython 运维

python django常用的函数

2017-07-11  本文已影响131人  廖马儿

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)
上一篇下一篇

猜你喜欢

热点阅读