0

我正在为每个用户创建一个页面,如何在我的 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))
4

2 回答 2

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))
于 2012-09-21T16:19:58.373 回答
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))
于 2012-09-21T16:23:05.230 回答