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)
原文地址:https://www.jianshu.com/p/a914625805cd
相关推荐
-
Django中的数据库访问优化——预加载关联数据 web开发
2019-2-24
-
使用PythonAnyWhere和GitHub免费部署Django网站 web开发
2019-4-27
-
如何更优雅地写Django REST framework web开发
2019-3-10
-
Django中的模板渲染是什么 web开发
2019-9-18
-
Nginx 优化静态文件访问 web开发
2019-10-4
-
DRF 与 React(Django2.1 + 测试 + xadmin + api文档)-翻译强化版 web开发
2019-2-21
-
中小团队基于Docker的devops实践 web开发
2019-6-8
-
Django跨域请求之JSONP和CORS web开发
2019-5-27
-
爬虫入门到精通-网页的解析(正则) web开发
2019-4-27
-
Django工程的分层结构 web开发
2019-9-18