Python Django使用HttpResponse返回图片并显示
views.py
def read_img(request):
"""
: 读取图片
:param request:
:return:
"""
try:
data = request.GET
file_name = data.get("file_name")
imagepath = os.path.join(settings.BASE_DIR, "static/resume/images/{}".format(file_name)) # 图片路径
with open(imagepath, 'rb') as f:
image_data = f.read()
return HttpResponse(image_data, content_type="image/png")
except Exception as e:
print(e)
return HttpResponse(str(e))
urls.py
url(r'^read_img/(?P<news_id>.+)/$',views.read_img,name="image"),
模板调用
<img src="{% url 'image' param.id %}" alt="{{param.id}}"/>
Python Django使用HttpResponse返回图片并显示的更多相关文章
- django 使用HttpResponse返回json数据为中文
之前我用django一般用JsonResponse来返回json数据格式 但是发现返回中文的时候会乱码 from django.http import JsonResponse def test(re ...
- python - django 使用ajax将图片上传到服务器并渲染到前端
一.前端代码 <!doctype html> <html lang="en"> <head> <meta charset="UT ...
- 解决django关于图片无法显示的问题
http://python.usyiyi.cn/django/index.html http://m.blog.csdn.net/blog/qingyuanluofeng/44877399 http: ...
- python Django注册页面显示头像
python Django注册页面显示头像(views) def register(request): ''' 注册 :param request: :return: ''' if request.m ...
- [原创]Python/Django使用富文本编辑器XHeditor上传本地图片
前言 为了在Django框架下使用Xheditor上传图片,居然折腾了我一个晚上.期间也遇到种种问题,网上相关资料极少.现在把经验分享给大家. 正文 xheditor篇 1.下载http://xhed ...
- Python Django 前后端数据交互 之 HttpRequest、HttpResponse、render、redirect
在使用三神装的时候,首先当然是得要导入它们: from django.shortcuts import HttpResponse, render, redirect 一.HttpRequest捕获 ...
- Django Admin 图片路径设置显示为图片(imageField显示方法设置)
一 使用环境 开发系统: windows IDE: pycharm 数据库: msyql,navicat 编程语言: python3.7 (Windows x86-64 executable in ...
- python 1: 解决linux系统下python中的matplotlib模块内的pyplot输出图片不能显示中文的问题
问题: 我在ubuntu14.04下用python中的matplotlib模块内的pyplot输出图片不能显示中文,怎么解决呢? 解决: 1.指定默认编码为UTF-8: 在python代码开头加入如下 ...
- django JsonResponse返回中文时显示unicode编码(\u67e5\u8be2)
django JsonResponse返回中文时显示unicode编码(\u67e5\u8be2) 关注公众号"轻松学编程"了解更多. 原因 这个unicode编码,是python ...
随机推荐
- golang基础归纳
1. hello-world package main import "fmt" func main(){ fmt.Println("Hello world, Go Go ...
- 简单介绍 Java 中的注解 (Annotation)
1. 例子 首先来看一个例子: @Override public String toString() { return "xxxxx"; } 这里用了 @Override, 目的是 ...
- linux系统编程之文件与io(四)
今天继续学习文件与io,主要是学习文件共享及文件.复制文件描述符,有点抽象,主要是概念上的理解,但是很重要,下面一一来分解: 文件共享: 回顾一下,在linux系统调用中,是通过文件描述符来访问文件的 ...
- 《少年先疯队》第九次团队作业:Beta冲刺第一天
1.1 今日完成任务情况 姚玉婷:酒店会员中房间管理功能的完善 马丽莎:登录功能测试文档的编写 张 琼:不同用户登录功能的测试,如管理员和会员 孙苗坤:登录功能测试用例的设计 1.2 明天任务安排 ...
- Oracle中修改某个字段可以为空
待修改字段假定为:shuifen 1.当该字段为空时,可直接修改: alter table reportqymx modify shuifen null; 2.当待修改字段不为空时:新增一列把要改变的 ...
- Burp Suite的代理Brup Proxy的使用详解
Burp Proxy 是Burp Suite以用户驱动测试流程功能的核心,通过代理模式,可以让我们拦截.查看.修改所有在客户端和服务端之间传输的数据.
- Django --- ajax结合sweetalert使用,分页器,bulk_create批量创建数据
目录 ajax结合sweetalert使用 bulk_create批量插入数据 分页器的使用 ajax结合sweetalert使用 ajax可以在不刷新页面的情况下与后端进行交互,在对数据进行操作的时 ...
- docker 构建自己的image 镜像文件
docker build 构建自己的镜像文件. 1.在本地工程中运行生成一个springboot的可运行的jar. 因为我习惯用eclipse,所以在eclipse下新建一个springboot的工程 ...
- Greenplum 激活standby 和恢复 master 原有角色
当Greenplum segment的primary出现问题时,FTS会监测到,GP会自动激活mirror.但是对于GP的master节点,虽然有standby,但是GP并不会自动来完成master和 ...
- learning java swing 双缓冲和键盘驱动
import javax.swing.*; import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.In ...