Book Image

Learning Website Development with Django

Book Image

Learning Website Development with Django

Overview of this book

Table of Contents (18 chapters)
Learning Website Development with Django
Credits
About the Author
About the Reviewers
Preface
Index

Improving the Interface with Messages


Although our implementation of user networks is working correctly, there is something missing. The interface does not tell the user whether an operation succeeded or failed. After sending an invitation, for example, the user is redirected back to the invitation form, with no feedback on whether the operation was successful or not. In this section, we are going to improve our interface by providing status messages to the user after performing certain actions.

Displaying messages to users is done using the message API, which is part of the authentication system. The API is simple; to create a message, you can use the following call:

request.user.message_set.create(
  message='Message text goes here.'
)

This call will create a message and store it in the database. Available messages are accessible from within templates through the variable messages. The following code iterates over messages and displays them in a list:

{% if messages %}
<ul>
    {%...