Django jQuery 查看用户问题
我似乎被困住了,不确定哪个是最好的方向。
我的项目中有一些应用程序,希望将三个视图合并到一个模板中。
我有一个用户个人资料,我想在其中显示他的信息、最新新闻提要以及他的照片
通过此我正在使用jQuery选项卡 >
我已经定义了三个选项卡,其中一个选项卡调用常规 div,另外两个选项卡是调用的 url。
地址栏在用户个人资料上显示以下内容 http://localhost:8000/profiles/profile_name/
在我的 views.py
中用于 wall
和 photos
外观如下所示
@login_required
def index(request, template_name='wall/_index.html'):
photos = Photos.objects.filter(user=request.user).order_by('-id')
context = { 'photos': photos, }
return render_to_response(template_name, context,
context_instance=RequestContext(request))
但是如果我然后查看我的个人资料,那就没问题,但是每当我切换到另一个用户个人资料时,它似乎仍然会显示我的一些信息。
我知道 request.user 正在查看登录的用户,我如何在地址栏中获取该用户并将其传递,以便它显示正确的信息,即如果 profile_name
= john 然后显示 johns 照片、最近的墙壁物品等。
I seem to be stuck and am not sure which is the best direction to take.
I have a few apps in my project and would like to combine three views into one template.
I have a userprofile in which I would like to display his info, latest news feeds and also his photos
Through this I am making use of jQuery tabs
I have defined my three tabs out of which one calls on a regular div and the other two are urls that get called in.
<a href="wall/recent">wall</a>
and <a href="photos/recent">photos</a>
the address bar reads the following when on a users profilehttp://localhost:8000/profiles/profile_name/
in my views.py
for wall
and photos
looks like the following
@login_required
def index(request, template_name='wall/_index.html'):
photos = Photos.objects.filter(user=request.user).order_by('-id')
context = { 'photos': photos, }
return render_to_response(template_name, context,
context_instance=RequestContext(request))
But if I then look at MY profile it is fine, but whenever I switch to another users profile it sill seems to display some of my information.
I know that request.user is looking at the logged in user, how do I obtain that user in the address bar and pass it on so it displays the correct info ie if profile_name
= john then displays johns photos, recent wall items etc.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果你有一个像这样的
urls.py
:那么你的视图代码可以像这样修改:
它的作用是将名称
prof_name
绑定到profiles/
之后和最终/
之前的 URL 位。给定 URL/profiles/john/
,您最终会调用index
视图,并将prof_name
设置为john
。If you've got a
urls.py
like this:Then your view code can be modified like this:
What this does is bind the name
prof_name
to whatever value is in the bit of the URL afterprofiles/
and before the final/
. Given the URL/profiles/john/
, you'd end up with theindex
view being called, withprof_name
set tojohn
.