-1
我需要根據用戶的登錄在我的模板,以顯示不同的按鈕的場景是我的模板顯示如下按鈕:如何根據用戶顯示模板不同的按鈕登錄在Django
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。 這裏是我的views.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 %}
你在堅持什麼?顯示一些代碼,你有什麼嘗試? –
我在我的問題中添加了一些代碼..但我認爲我的views.py是不正確的。因爲它顯示了關鍵錯誤user_id .. –
@HananFaisal你有'auth'模塊在'INSTALLED_APPS'設置中。 py'? –