Django 问题:我想发送到电子邮件的发票
这是一个与 Django 相关的问题。我有一张从显示信息的数据库创建的发票。现在我想知道是否可以将这些详细信息发送到电子邮件地址。我尝试在 http://docs.djangoproject.com/en/ 查看此页面dev/topics/email/,但我不知道我是否在寻找它。我假设我可能还需要创建一个表单。
编辑:我想要这样的东西 - 但我想返回整个表单。不仅仅是主题。检查视图。抱歉回复晚了。
# urls.py
urlpatterns = patterns('',
(r'^index/add_invoice/$', add_invoice),
(r'^index/invoice/$', invoice_info),
(r'^index/invoice_details/(?P<id>\d+)/$', invoice_details),
)
#views.py
@login_required
def add_invoice(request):
if request.method == 'POST':
form = InvoiceForm(request.POST or None)
if form.is_valid():
form.save()
send_mail('Subject here', 'Here is the message.', '[email protected]', ['[email protected]'], fail_silently=False
)
return HttpResponseRedirect('/index/invoice/')
else:
form = InvoiceForm()
return render_to_response('add_invoice.html', {'form': form}, context_instance=RequestContext(request))
#add_invoice.html
{% extends "base.html" %}
{% block content %}
<font face="verdana,news gothic,arial,heltevica,serif">
<h3> Add Invoice</h3>
<font face="verdana,news gothic,arial,heltevica,serif">
<form method= "POST" action="">
<div id="form">
<table>
{{form.as_table}}
</table>
<div align="center" STYLE=" margin-right:270px">
<input type="submit" value="Submit" STYLE="background-color:#E8E8E8; color:#181818 "/>
</div>
</div>
</form>
{% endblock %}
this is a Django related question. I have an invoice that I have created from a database which displays the information. Now I want to know is if I can send these details to an email address. I have tried looking at this page at http://docs.djangoproject.com/en/dev/topics/email/, but I don't know if I am looking for that. I am assuming I need to create a form maybe as well.
Edit: I want something like this - but I want to return the whole form. Not just the subject. Check the views. Apologies for the late reply.
# urls.py
urlpatterns = patterns('',
(r'^index/add_invoice/
, add_invoice),
(r'^index/invoice/
, invoice_info),
(r'^index/invoice_details/(?P<id>\d+)/
, invoice_details),
)
#views.py
@login_required
def add_invoice(request):
if request.method == 'POST':
form = InvoiceForm(request.POST or None)
if form.is_valid():
form.save()
send_mail('Subject here', 'Here is the message.', '[email protected]', ['[email protected]'], fail_silently=False
)
return HttpResponseRedirect('/index/invoice/')
else:
form = InvoiceForm()
return render_to_response('add_invoice.html', {'form': form}, context_instance=RequestContext(request))
#add_invoice.html
{% extends "base.html" %}
{% block content %}
<font face="verdana,news gothic,arial,heltevica,serif">
<h3> Add Invoice</h3>
<font face="verdana,news gothic,arial,heltevica,serif">
<form method= "POST" action="">
<div id="form">
<table>
{{form.as_table}}
</table>
<div align="center" STYLE=" margin-right:270px">
<input type="submit" value="Submit" STYLE="background-color:#E8E8E8; color:#181818 "/>
</div>
</div>
</form>
{% endblock %}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不,您需要创建模板,然后您需要处理它然后你需要发送。
No, you need to create a template and then you need to process it and then you need to send it.
您必须使用模板加载器来加载消息模板并使用所需的变量创建上下文,然后将模板呈现为字符串。请参阅以下粗略(且不完整)的示例:
You have to use the template loader to load your message template and create a context with the variables you want and then render the template into string. See the following crude (and incomplete) example: