查找用户名

时间:2012-09-21 16:18:05

标签: django

我正在为每个用户创建一个页面,如何在我的django用户模型中查找用户名

views.py
    def user_page(request,user):
    user = User.objects.filter(user =user.username)
    return render_to_response('user_page.html',"user":user,context_instance=RequestContext(request))

2 个答案:

答案 0 :(得分:0)

def user_page(request,username):
    user = User.objects.filter(username=username)
    return render_to_response('user_page.html',{"user":user},context_instance=RequestContext(request))

答案 1 :(得分:0)

from django.contrib.auth.models import User
from django.shortcuts import get_object_or_404

def user_page(request, username):
    user = get_object_or_404(User, username=username)

    return render_to_response('user_page.html',{"user":user},context_instance=RequestContext(request))