2012-12-08 27 views
0

我一直在爲我的django網站製作用戶個人資料頁面,但我無法弄清楚我的邏輯在下面的函數中是錯誤的。問題是我試圖爲訪問者加載自己的個人資料頁面或其他用戶的個人資料時呈現不同的模板。即使request.user匹配「name」(這是從url加載的字符串),它仍然呈現第二個模板。這意味着即使在a = name時,它也不會返回true。誰能告訴我錯誤在哪裏?Django用戶匹配錯誤

def profile2(request, name): 
    a = request.user 
    if a is name: 
     return render_to_response("profile.html", context_instance=RequestContext(request)) 
    return render_to_response("diffprofile.html", {'name':name}, context_instance=RequestContext(request)) 

回答

0

沒關係,只是意識到我需要給用戶「==」,而不是「是」,是因爲該字符串傳遞進來,而不是在功能上作出?

+0

http://stackoverflow.com/questions/1504717/python-vs-is-comparing-strings-is-fails-sometimes-why –

+0

無論如何,你寧願比較'request.user.username'和'name'但不是'request.user' –