我想從django 1.3的圖像發送HTML電子郵件,但我的圖像未加載。以下是我的view.pyDjango發送帶圖像的HTML電子郵件
email_data = {
# Summary data
'user_name':user_name,
'points':user.numOfPoints,
}
email_data = RequestContext(request, email_data)
t = get_template('user_email.html')
content = t.render(email_data)
msg = EmailMessage(subject='User Email', content, '[email protected]', ['[email protected]'])
msg.content_subtype = "html"
msg.send()
我的模板(「user_email.html」)看起來像以下
<html>
<body>
Hello {{user_name}},
Your point score is: {{points}}
Thank you for using our app.
<img src="{{ STATIC_URL }}images/footer.jpg" alt="" />
<body>
</html>
的形象是我的應用程序文件夾的靜態/圖像文件夾內的地方。但是,當收到電子郵件時,它沒有圖像。
在我的settings.py,我有以下
TEMPLATE_CONTEXT_PROCESSORS = (
'django.contrib.auth.context_processors.auth',
'django.core.context_processors.debug',
'django.core.context_processors.i18n',
'django.core.context_processors.media',
'django.core.context_processors.static',
'django.contrib.messages.context_processors.messages',
)
STATIC_URL = '/static/'
請回覆我缺少的是什麼?
感謝,
什麼是郵件中圖像的呈現網址? – iMom0
渲染圖像的網址是 http://static/images/footer.jpg –