Reputation: 1469
Using inclusion_tag I am trying to create a header with user links depending on the login status (eg. If user logged; display username and log out link, otherwise log in and sign up link). To do that, I created my own Login App so I am not using any Django's MIDDLEWARE_CLASSES
What am I missing? Any help would be appreciated, thanks!
Exception Type: KeyError
Exception Value: 'request'
from django import template
from login.models import Login
from test.views import read_secure_cookie
def login_finder(context):
user = {}
active_user = read_secure_cookie(context['request'], 'user_id')
id = active_user[0]
try:
login = Login.objects.filter(id=id).get()
except Login.DoesNotExist:
return None
user['user'] = login.username
return user
register = template.Library()
register.inclusion_tag('login/header.html', takes_context=True)(login_finder)
def frontpage(request):
params = {}
return render_to_response('frontpage.html',
params,
context_instance=RequestContext(request))
{% extends "base.html" %}
{% load login_tags %}
{% block title %}{{ block.super }}{% endblock %}
{% login_finder %}
Upvotes: 0
Views: 336
Reputation: 599630
The request context processor is not active by default. You need to add it to TEMPLATE_CONTEXT_PROCESSORS
in settings.py yourself.
Upvotes: 1