问题描述
网上有很多youtube或说明,但我找不到任何可以将其应用于博客/创建的内容。我的意思是,我想让电子邮件自动发送给创建新帖子的人。
这是下面的博客/views.py;
from django.core.mail import send_mail
class PostCreate(LoginrequiredMixin,CreateView):
model = Post
fields = [
'title','content','head_image','category','tags'
]
def form_valid(self,form):
current_user = self.request.user
if current_user.is_authenticated:
form.instance.author = current_user
return super(type(self),self).form_valid(form)
else:
return redirect('/blog/')
我设置 settings.py 如下:
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_PORT = 587
EMAIL_HOST_USER = 'example@gmail.com' # my email address I put
EMAIL_HOST_PASSWORD = '****************' # the password I put
EMAIL_USE_TLS = True
EMAIL_USE_SSL = False
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
我现在有一个项目要做...我没有太多时间复习和学习...我是一个初学者...期待从这里得到一些帮助
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)