There are quite a few youtube or instructions online but I could not find anything to apply this to blog/create. What I mean by that, I would like to have email to be sent automatically to the guy who create a new post.
Here is the blog/views.py below;
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/')
I did setup settings.py like below:
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'
I have a project to do right now... I don't have much time to review and study again... I am such a beginner... looking forward to having some help from here