i want to add an 'EDIT' link for each posts on index page. but before show this link ; i need to check if session is registered. i mean i need something like this :
{% if session.name=='blabla' %}
<a href="#">Edit</a>
{% endif %}
i have django.core.context_processors.request on template context processors.
thank you
edit :
here is my detailpage view :
def singlePost(request,postslug):
post = get_object_or_404(Post, slug=postslug)
context = {'post':post}
return render_to_response('detail.html',context,context_instance = RequestContext(request))
when i try this :
def singlePost(request,postslug):
session=request.session['loggedin']
post = get_object_or_404(Post, slug=postslug)
context = {'post':post}
return render_to_response('detail.html',context,context_instance = RequestContext(request,{'session':'session',}))
it gives template syntax error ( render error)
i tried this :
{% if request.session.name=='blablabla' %}
here is the error :
TemplateSyntaxError at /post/viva-barca
Could not parse the remainder: '=='djangoo'' from 'request.session.name=='djangoo''
i found a different way.
{% if post.owner == user %}
<div class="right"><a href="{% url editpost post.id %}">Edit</a></div>
{% endif %}
in this way ; i can control user auth too. because there r many users which have their own accounts and posts which are listed in index.html. if i dont write this control ; x user can edit other y user's post. but now only logged in users can edit their own posts.
and if there is no any logged in user ; the 'EDIT' link is not shown.