2012-09-21 97 views
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)) 

回答

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)) 
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))