My blog development (027)

Posted May 25, 20202 min read

image.png
In the comment/views.py update \ _comment method, the code for sending email notifications is added. The first thing to see is whether to reply to my comment or comment on the blog post. The way to distinguish is to see if he has Parent:reverse for reverse analysis Draw its link;
image.png
Then use the reverse method in blog/models.py to reverse parse and return the corresponding blog \ _pk value:
image.png
Similarly, add a get \ _email to models.py to return to the view function
image.png
But now because sending mail needs to wait for a while, it is more time-consuming, so use asynchronous operations:
image.png
Use multithreading in comment/models.py and add send \ _mail method to send mail
image.png
image.png
modify the send \ _mail method in views.py,
new function:
image.png
The content of the email sent:the style is ugly
image.png
Then add the html \ _message field to the run function in comment/models.py:
image.png
Then add content to the text in the send \ _mail method:
image.png
But when our html is more complicated, the content of the text here is very messy, you can call the template to generate an html, add in comment/models.py:from django.template.loader import render \ _to \ _string:
Create a templates folder in the comment, and then create a comment folder(the same principle as templates/user in the user):then create a send \ _mail.html file in comment/templates/comment:
image.png
Use the render \ _to \ _string method in comment/models.py to call the above send \ _mail.html template:

However, using render \ _to \ _string here may automatically add a p tag to our comments(in the email sent to us), and no reason has been found here:suspected to be related to the qq mailbox
image.png
Finally, the method of deployment to the Internet:
image.png