gpt4 book ai didi

html - 直接从 django 模板发送电子邮件

转载 作者:行者123 更新时间:2023-12-01 15:19:07 26 4
gpt4 key购买 nike

我有一个 Django 项目。它的 index.html 页面包含一个带有提交按钮的表单。我想在此 index.html 页面中包含 django-template 以发送包含此表单数据的电子邮件。可以不用任何 python 代码吗?就像:

{% send_mail( {{ request.GET.to }}, {{ request.GET.subject }}, {{ request.GET.message }} %}

附言我是 django 的新手。

最佳答案

这行不通。 Django 模板不是为直接调用 python 模块/方法而设计的。您可以创建一个模板标签,或者在点击时触发一个 url/view 来发送电子邮件。

来自philosophy of django template language

If you have a background in programming, or if you’re used to languages which mix programming code directly into HTML, you’ll want to bear in mind that the Django template system is not simply Python embedded into HTML. This is by design: the template system is meant to express presentation, not program logic.

有关如何创建 template tags 的文档

这是一个很好的教程,讨论 email sending functionality through views. py

关于html - 直接从 django 模板发送电子邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25624817/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com