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. Flask之threading.loacl方法

    一.threading.loacl方法 import threading import time class Foo: pass foo = Foo() def func(num): foo.num ...

  2. @RequestMapping中的注解

    在org.springframework.spring-web的jar包中在以下层级下: org.springframework.web.bind.annotation; // // Source c ...

  3. Jmeter4.0 _Beanshell解析并获取json响应数据数组长度

    我们在做jmeter接口测试的时候,有时候碰到开发没返回数据total,只返回了一条条记录,可是呢,我们又需要知道到底返回了多少条数据时,咋办呢?咋办呢?咋办呢? 不要急,接下来,让我们见证奇迹是如何 ...

  4. sshd安全加固

    常见的防护措施: ——用户限制,黑白名单 ——更改验证方式(密码——>密钥对) ——防火墙..... 修改 sshd 配置文件 /etc/ssh/sshd_config -port 3389 # ...

  5. Yum下载rpm包、不分析依赖关系强制安装

    在安装包后面加两个参数 --nodeps --force 如下: [root@sh158-xen data]#rpm -ivh MySQL-server-5.5.24-1.linux2.6.x86_6 ...

  6. python3 xml_to_dict、dict_to_xml等互相转换的方法

    from basic_config_vars.config_vars import moviesAllFilePath,moviesFilePath #自定义的一些文件变量 import xmltod ...

  7. [转]Linux网络 - 数据包的接收过程

    转, 原文: https://segmentfault.com/a/1190000008836467 ------------------------------------------------- ...

  8. mysql.jdbc.Driver异常总结

    1.registered the JDBC driver [com.mysql.jdbc.Driver] but failed to unregister it when the web applic ...

  9. EF映射——从数据库更新实体

    最近在做ITOO项目,由于更新了数据库,需要重新从数据库映射到实体,本来看过关于EF的学习资料,直接可以从数据库更新到实体,但这种小事也是有很多问题的,必须在更新的时候做好选择.下面分享一下如何从数据 ...

  10. python获取当前文件夹下所有文件名【转】

    os 模块下有两个函数: os.walk() os.listdir() 1 # -*- coding: utf-8 -*- 2 3 import os 4 5 def file_name(file_d ...