0
假設我有Django的父子關係模板
- mainprofile.html這是我從views.profile渲染和
- followers.html這是我從views.followers渲染
當我點擊追隨者按鈕時,它會調用views.followers 並呈現追隨者並將其正確插入主配置文件。
我想要做什麼:
當我這樣做,我失去了父頁面上的所有配置文件信息(主檔次),如userinfo.username 我如何克服這個問題?
mainprofile.html:
{% extends 'layout/master.html' %}
{% load sharedtags %}
{% block content %}
{{ userinfo.username }}
...some profile information...
followers_button
{% block right_side_main_layout %}
... some info ...
{% endblock right_side_main%}
{% endblock content%}
followers.html:
{% extends 'mainprofile.html' %}
{% block right_side_main_layout %}
... list of followers ...
{% endblock right_side_main_layout %}
views.py:
def profile(request,username):
userdetail = AuthUser.objects.filter(username=username)
template='profil/mainprofile.html'
context = RequestContext(request, {'userinfo': userdetail })
return render_to_response(template, context)
def followers(request, username):
followers = Followers.objects.filter(username=username)
template = 'profil/em-profile-follower.html'
context = RequestContext(request,{'followers': followers})
return direct_to_template(template,context)
感謝。