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返回图片并显示的更多相关文章

  1. django 使用HttpResponse返回json数据为中文

    之前我用django一般用JsonResponse来返回json数据格式 但是发现返回中文的时候会乱码 from django.http import JsonResponse def test(re ...

  2. python - django 使用ajax将图片上传到服务器并渲染到前端

    一.前端代码 <!doctype html> <html lang="en"> <head> <meta charset="UT ...

  3. 解决django关于图片无法显示的问题

    http://python.usyiyi.cn/django/index.html http://m.blog.csdn.net/blog/qingyuanluofeng/44877399 http: ...

  4. python Django注册页面显示头像

    python Django注册页面显示头像(views) def register(request): ''' 注册 :param request: :return: ''' if request.m ...

  5. [原创]Python/Django使用富文本编辑器XHeditor上传本地图片

    前言 为了在Django框架下使用Xheditor上传图片,居然折腾了我一个晚上.期间也遇到种种问题,网上相关资料极少.现在把经验分享给大家. 正文 xheditor篇 1.下载http://xhed ...

  6. Python Django 前后端数据交互 之 HttpRequest、HttpResponse、render、redirect

    在使用三神装的时候,首先当然是得要导入它们: from django.shortcuts import HttpResponse, render, redirect   一.HttpRequest捕获 ...

  7. Django Admin 图片路径设置显示为图片(imageField显示方法设置)

    一  使用环境 开发系统: windows IDE: pycharm 数据库: msyql,navicat 编程语言: python3.7  (Windows x86-64 executable in ...

  8. python 1: 解决linux系统下python中的matplotlib模块内的pyplot输出图片不能显示中文的问题

    问题: 我在ubuntu14.04下用python中的matplotlib模块内的pyplot输出图片不能显示中文,怎么解决呢? 解决: 1.指定默认编码为UTF-8: 在python代码开头加入如下 ...

  9. django JsonResponse返回中文时显示unicode编码(\u67e5\u8be2)

    django JsonResponse返回中文时显示unicode编码(\u67e5\u8be2) 关注公众号"轻松学编程"了解更多. 原因 这个unicode编码,是python ...

随机推荐

  1. (critical) chassis-frontend.c:122: Failed to get log directory, please set by --log-path

    Atlas MySQL 读写分离 [root@localhost ~]# /usr/local/mysql-proxy/bin/mysql-proxy test start2019-05-07 10: ...

  2. 使用IDEA将springboot框架导入的两种方法

    第一种新建Maven,导入springboot所依赖的jar包   1.新建一个maven项目,下一步命名,保存文件地址,点击完成         2.进去springboot下载(点击进入),复制p ...

  3. [daily][archlinux] pacman 安装软件时404的问题

    时常,我们在archlinux上pacman安装一个软件时,会遇见如图这样的问题: “The requested URL returned error: 404”  [classic_tong @ 2 ...

  4. Vuex状态管理总结

    一.什么是 Vuex 1.Vuex 是一个专为 Vue.js 应用程序开发的状态管理模式 2.Vuex 采用集中式存储和管理应用中所有组件的状态 3.Vuex 应用的核心是 store(仓库)-- 包 ...

  5. 微信小程序之循环<block></block>

    (1)<block></block>标签 block常用于结合循环 <block wx:for="{{array}}" wx:key="{{ ...

  6. spring DefaultListableBeanFactory 概述

                 有人说,DefaultListableBeanFactory是spring的发动机,其实重要性不为过.TA的整体类图如下:     这里先概述接口部分:   BeanFact ...

  7. 《你们都是魔鬼吗》实验十二 团队作业八:Alpha冲刺

    <你们都是魔鬼吗>第八次团队作业:Alpha冲刺 项目 内容 这个作业属于哪个课程 任课教师博客主页链接 这个作业的要求在哪里 作业链接地址 团队名称 你们都是魔鬼吗 作业学习目标 软件测 ...

  8. HP DL388 Gen9 Raid P440ar 工具

    HP DL388 Gen9 服务器raid升级P440ar,原先的hpacucli 不能使用,新的工具为hpssacl hpssacli-2.10-14.0.x86_64.rpm 下载地址:wget ...

  9. matlat保存矩阵数据

    a=[1 2 3; 4 5 6]; fid = fopen('haha.txt', 'w+');fprintf(fid,'%8.4f %8.3f %d\n', a');fclose(fid); typ ...

  10. C#格式化字符串使用

    1 前言 如果你熟悉Microsoft Foundation Classes(MFC)的CString,Windows Template Library(WTL)的CString或者Standard ...