我正在使用mezzanine作为项目,并且需要在添加新帖子时通知订阅者,我想编写自己的视图功能,以便在发布新帖子时,我可以执行以下操作: / p>
# pseudo_code.py
blogposts.onAdd(notify())
def notify():
email(users)
答案 0 :(得分:0)
您需要的一切都在文档中:
https://docs.djangoproject.com/en/1.8/topics/email/
http://mezzanine.jupo.org/docs/content-architecture.html#page-processors
以下是我的夹层项目中的一些代码:
models.py
from mezzanine.pages.models import Page
from django.db import models
class WorkOrderPage(Page): #create model that inherits from page
header = models.CharField(max_length=3000,null=True)
admin.py
from .models import WorkOrderPage
from django.contrib import admin
from mezzanine.pages.admin import PageAdmin
admin.site.register(WorkOrderPage, PageAdmin) //make page available to admin
page_processors.py
from mezzanine.pages.page_processors import processor_for
from .models import WorkOrderPage
from django.core.mail import send_mail
from django.core.mail import EmailMultiAlternatives
class NewWorkOrderForm(forms.Form):
//create form
@processor_for(WorkOrderPage)
def newworkorder_form(request, page):
form = NewWorkOrderForm()
if request.method == "POST":
form = NewWorkOrderForm(request.POST)
if form.is_valid():
from_email = 'xx@xx.com'
to_email = 'yy@yy.com'
subject, from_email, to = 'subject text', from_email, to_email
text_content = 'content of email'
html_content = 'html content'
msg = EmailMultiAlternatives(subject text, text_content, from_email, [to])
msg.attach_alternative(html_content, "text/html")
msg.send()
return redirect('/redirect to?')
return {"form": form}
因此,您需要创建一个工作订单页面'在管理员中, 该页面将有一个表单,当他们提交表单时会发送一封电子邮件。