zoukankan      html  css  js  c++  java
  • 14.django返回展示一张图片

    urlpatterns = [
        path('admin/', admin.site.urls),
        # 使用django返回一张土图片的时候需要间接的访问一个中间接口,是html页面的中的img的src自己去请求服务器的后台的一个接口,这个时候就需要用到模板自己的反向解析了
        url("^go_html/$", views.go_html),
        url("^show_log/$", views.show_logo, name="image"),  
    ]
    
    --------------------------------------------------------------------------------------
    
    def show_logo(request):
        path = r"C:\Users\18309\PycharmProjects\untitled\static\img\123.jpg"
        file_one = open(path, "rb")
        return HttpResponse(file_one.read(), content_type='image/jpg')
    
    
    def go_html(request):
        return render(request, "show_img.html")
    
    
    ---------------------------------------------------------------------------------------
    <div style=" 200px; height: 200px; background-color: gray">
        <img src="{% url 'image' %}" alt="图片">
    </div><div style=" 200px; height: 200px; background-color: gray">
        <img src="{% url 'image' %}" alt="图片">
    </div>
    

      

  • 相关阅读:
    ORACLE常用SQL优化hint语句
    TestNG 入门教程
    博客迁移
    WebMvcConfigurer
    Nginx 配置
    SpringBoot部署
    MyBatis 动态 SQL
    Spring Boot 验证表单
    Spring Boot session与cookie的使用
    Spirng MVC 重定向传递对象
  • 原文地址:https://www.cnblogs.com/liuzhanghao/p/11766460.html
Copyright © 2011-2022 走看看