python django常用的函数

作者: 廖马儿 | 来源:发表于2017-07-11 23:13 被阅读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)

相关文章

网友评论

    本文标题:python django常用的函数

    本文链接:https://www.haomeiwen.com/subject/omymhxtx.html