1. | Stop the development server.
|
2. | Open the iFriends/Log/models.py file in an editor.
|
3. | Add the ResponseEvent model to the file, as shown in Listing 19.9, to define a ResponseEvent object that can store information about the response. |
4. | Save the iFriends/Log/models.py file.
|
5. | Synchronize the database using the manage.py syncdb command from the root of the iFriends project.
|
6. | Open the django/middleware/custom.py file in your Django installation.
|
7. | Add the following import to the file, as shown in Listing 19.10, to import the ResponseEvent object you defined in step 3:
from iFriends.Log.models import ResponseEvent
|
8. | Add the CustomResponseLogger middleware class definition to the file and define the process_response() function, as shown in Listing 19.10. This will collect information about the view request and store it in a ResponseEvent object in the database. |
9. | Save the django/middleware/custom.py file.
|
10. | Create and open a file called iFriends/templates/Custom/view_response_log.html in an editor. |
11. | Add the contents shown in Listing 19.11 to the file. |
12. | Save the iFriends/templates/Custom/view_response_log.html file.
|
13. | Open the iFriends/Custom/views.py file in an editor.
|
14. | Add the following code to the view_log() view function, as shown in Listing 19.12. It sets lTemplate to the view_response_log.html file and logList to the ResponseEvent objects if evType is set to response:
elif evType == "response":
lTemplate = 'Custom/view_response_log.html'
logList = ViewResponse.objects.all()
|
15. | Save the iFriends/Custom/views.py file.
|
16. | Open the iFriends/settings.py file in an editor.
|
| |
17. | Add the following line to the MIDDLEWARE_CLASSES setting to install the CustomResponseLogger application:
'django.middleware.custom.CustomResponseLogger',
|
18. | Save the iFriends/settings.py file.
|
19. | Start the development server.
|
20. | Access several nonadmin web pages in the iFriends site. Access the following URL to view the log report, as shown in Figure 19.3, generated by the CustomResponseLogger application:
http://127.0.0.1:8000/admin/view_log/response/
|