Sharing posts by email
First, we will allow users to share posts by sending them emails. Take a short time to think how you would use views, URLs, and templates to create this functionality using what you have learned in the preceding chapter. Now, check what you need in order to allow your users to send posts by email. You will need to do the following things:
- Create a form for users to fill in their name and email, the email recipient, and optional comments
- Create a view in the
views.py
file that handles the posted data and sends the email - Add a URL pattern for the new view in the
urls.py
file of the blog application - Create a template to display the form
Creating forms with Django
Let's start by building the form to share posts. Django has a built-in forms framework that allows you to create forms in an easy manner. The forms framework allows you to define the fields of your form, specify how they have to be displayed, and indicate how they have to validate input data. The Django forms framework...