我正在使用reportlab pdfgen创建PDF.在PDF中有一个由drawImage
创建的图像.为此,我需要图像的URL或视图中图像的路径.我设法构建了URL,但是如何获得图像的本地路径呢?
如何获取URL:
prefix = 'https://' if request.is_secure() else 'http://'
image_url = prefix + request.get_host() + STATIC_URL + "images/logo_80.png"
我正在使用reportlab pdfgen创建PDF.在PDF中有一个由drawImage
创建的图像.为此,我需要图像的URL或视图中图像的路径.我设法构建了URL,但是如何获得图像的本地路径呢?
如何获取URL:
prefix = 'https://' if request.is_secure() else 'http://'
image_url = prefix + request.get_host() + STATIC_URL + "images/logo_80.png"
# Older Django <3.0 (also deprecated in 2.0):
from django.contrib.staticfiles.templatetags.staticfiles import static
# Django 3.0+
from django.templatetags.static import static
url = static('x.jpg')
url现在包含'/static/x.jpg'
,假设静电路径为'/static/'