I'm writing django-based forum, and i've decided it would be suitable for user to browse his last pages. Also, user tracking middleware can be a good aid for suggestions, and so on.
I think, the easiest way to do it is to use the
Django Middleware
, but i ran into a problem: how to get the title of the page being rendered? Overrideprocess_template_response
? Can i get the{% block title %}
there?The second server-side way is to use a template tag, i think. In the easiest case, it should should look like
{% block title %}{% last_visited _("Page title") %}{% endblock %}
.The third, stupid way: make an ajax script, that will push current user's opened page with title into his session. So, this method will just avoid us getting the page title.
I think, the right way is to get the title
block from a template context in middleware. How can i do it?
Thanks.
UPDATE
Made the gist with realisation of the second method using templates
and django.cache
. The simplest usage:
{% block title %}{% save_visited _("Profile setup") %}{% endblock %}
...
{% load_visited 'visited' %}
{% for title, uri, dt in visited %}
<a href="{{ uri }}">{{ title }} {% trans "at" %} {{ dt }}</a><br/>
{% endfor %}
Also, i'm still looking for a method allows to get the page's {% block title %}
in the middleware. Of course, i can use, i.e., lxml
parser and get the title
in the process_response
method, but it is an ugly overkill.
Thanks for any advice.