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="width: 200px; height: 200px; background-color: gray"> <img src="{% url 'image' %}" alt="圖片"> </div><div style="width: 200px; height: 200px; background-color: gray"> <img src="{% url 'image' %}" alt="圖片"> </div>