在Django表单中通过电子邮件发送会议邀请可以通过以下步骤实现:
from django import forms
class MeetingForm(forms.Form):
email = forms.EmailField(label='Email')
from django.core.mail import send_mail
from django.shortcuts import render
def send_invitation(request):
if request.method == 'POST':
form = MeetingForm(request.POST)
if form.is_valid():
email = form.cleaned_data['email']
subject = '会议邀请'
message = '您被邀请参加会议。'
sender = 'your_email@example.com'
recipient_list = [email]
send_mail(subject, message, sender, recipient_list)
return render(request, 'success.html')
else:
form = MeetingForm()
return render(request, 'invitation.html', {'form': form})
<form method="post" action="{% url 'send_invitation' %}">
{% csrf_token %}
{{ form.as_p }}
<button type="submit">发送邀请</button>
</form>
这样,当用户填写表单并提交后,Django会使用配置好的邮件设置发送会议邀请到用户输入的电子邮件地址。
请注意,以上代码仅为示例,你需要根据自己的实际需求进行适当的修改和完善。
领取专属 10元无门槛券
手把手带您无忧上云