我需要根据用户的登录在我的模板中显示不同的按钮。场景是我的模板显示跟随按钮:
Check whether the user logged in or not-
if user logged in-
check which channel he follwed:
if he followed any channel
beside that channel name show "followed" button
else
show "follow" button with the path follow_save
elif user not logged in:
show follow button with the path follow_save
我被卡住了怎么办?这是视图任务还是模板任务?怎么做?你们专家的任何帮助都会救我..我也想从会话中获取 user_id。这是我的意见.py
e= EventArchiveGallery.objects.all()
user = request.session['user_id']
if user:
j = EventArchiveGallery()
joining_list = j.joiningList(user)
return render_to_response('gallery/allevents.html',
{
'joining_list':joining_list,
},
context_instance=RequestContext(request)
)
这是我的模板:
{% for event in live %}
<p>Event Title:{{event.event_title}}<p/>
<p>Channel Name:{{event.channel_id.channel_title}}</p>
<p>Event Description{{event.event_description}}</p>
{% if event in joining_list %}
<p>followed</p>
{%else%}
<p>follow</p> #I have wanted to show follow_save function call from this button,when user clicked
{endif%}
{% endfor %}