iT邦幫忙

0

django ImageField圖片如何透過Line notify傳出去

在django models中有個圖片欄位
在admin中是可以正常看到圖片
但是想要透過Line notify傳圖片出去
就會出現FileNotFoundError
圖片大小大概300KB
想請教大神因應之道

setting.py

MEDIA_URL = '/media/'
MEDIA_ROOT = BASE_DIR / 'media'

urls.py

re_path('^media/(?P<path>.*)/$', serve, {"document_root": MEDIA_ROOT}),

models.py

class Equipment(models.Model):
    eimage = models.ImageField(upload_to='upload/photo/%Y/%m', verbose_name='照片', null=True,default=r'/default.jpg')

views.py

def Line_Notify(token, message, img):
    headers = {
        "Authorization": "Bearer " + token,
        "Content-Type": "multipart/form-data",
    }
    param = {'message': message}
    image = {'imageFile': open(img, 'rb')}
    r = requests.post("https://notify-api.line.me/api/notify", headers=headers, params=param, files=image)
    return r.status_code

Line_Notify(token, '文字', img)
你用絕對位置試試看
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友回答

立即登入回答