My blog development (027)

Time:2021-7-19

My blog development (027)
Update in comment / views. PY_ The code of sending email notification is added in the comment method. First of all, it depends on whether to reply to my comments or comment on the blog. The distinguishing method is to see whether the parent: reverse is used to parse the variable backward to get its link;
My blog development (027)
Then use the reverse method in blog / models. Py to parse and return the corresponding blog_ PK value:
My blog development (027)
Also add a get in models. Py_ Email is returned to the view function
My blog development (027)
But now, because sending e-mail needs to wait, which is time-consuming, asynchronous operation is used
My blog development (027)
Use multithreading in comment / models. Py and add send_ Mail method to send mail
My blog development (027)
My blog development (027)
Modify send in views.py_ Mail method,
New features:
My blog development (027)
The content of the email sent: the style is ugly
My blog development (027)
Add HTML to the run function in comment / models. Py_ Message field:
My blog development (027)
And then in send_ Add content to text in mail method:
My blog development (027)
However, when our html is complex, the content of the text here is very messy. You can call the template to generate an HTML, and add from django.template.loader import render in comment / models.py_ to_ string:
Create a Templates folder in comment, and then create a comment folder in it (the same principle as templates / user in user): then create a send folder in comment / templates / comment_ Mail.html file:
My blog development (027)
Using render in comment / models. PY_ to_ The string method calls send above_ Mail.html template:

But here we use render_ to_ String may automatically add a p tag to our comments (in the email sent to us), but we can’t find the reason here: it may be related to QQ email
My blog development (027)
Finally, the deployment method to the Internet is as follows:
My blog development (027)