Reputation: 31
I need to have access to some request data (username) into a template used in a generic list view. I serched django documentation but this subject is not so clear (to me) at a first glance.
My situation is like this:
**urls.py:**
from django.conf.urls.defaults import patterns
from django.views.generic.base import TemplateView
...
urlpatterns = patterns('',
...
(r'^pattern.html', TemplateView.as_view(template_name="template_name.html")),
...
)
** template_name.html **
{% extends "base.html" %}
{% block title %}My title{% endblock %}
{% block content %}
<h2>My heading</h2>
<a href="{% url path.to.my.view.view_name_1 %}">link text 1</a> |
<a href="{% url path.to.my.view.view_name_2 %}">link text 2</a> |
<a href="{% url path.to.my.view.view_name_3 request.username %}">link for {{username}}</a> |
{% endblock %}
Here (template_name.html) is where I want to use the request data. To compose a link to another view passing as parameter request.user
This post says tels somthing about generics but its not exactly what i need.
Upvotes: 0
Views: 146
Reputation: 599630
{{ user.username }}
is always available in a generic view, because of the auth
context processor. If you need anything else from the request, you'll need to add the request
context processor.
Upvotes: 2