假设我有
当我点击关注者按钮时,它会调用views.followers 并呈现关注者并将其正确插入主要配置文件。
我想做什么:
当我这样做时,我丢失了父页面(mainprofile)上的所有配置文件信息,例如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)
感谢。
答案 0 :(得分:1)
您还必须将AuthUser实例添加到followers
视图。
def followers(request, username):
followers = Followers.objects.filter(username=username)
userdetail = AuthUser.objects.filter(username=username)
template = 'profil/em-profile-follower.html'
context = RequestContext(request,{'followers': followers, 'userinfo': userdetail})
return direct_to_template(template,context)
现在,您还将在此模板(和视图)
中拥有userinfo我不确定你的模特看起来如何。但我认为AuthUser有一个ForeignKeyField(Follower)。
如果您将此字段设为related_name
(例如'关注者'),则可以执行以下操作:
userdetail = AuthUser.objects.filter(username=username)
然后在您的模板中,您可以通过以下方式访问您的关注者:
userdetail.followers