我試圖做一個應用程序,寵物的所有者可以創建自己的配置文件並上傳他們的寵物的圖片。Django錯誤的本地變量'人'參考前
當用戶創建一個帳戶或登錄時,他會被重定向到配置文件中。配置文件頁面應顯示他的信息,例如名稱,而不是我收到此錯誤。
UnboundLocalError at /profile/
local variable 'Person' referenced before assignment
Request Method: GET
Request URL: /profile/
Django Version: 1.4.3
Exception Type: UnboundLocalError
Exception Value: local variable 'Person' referenced before assignment
Traceback Switch to copy-and-paste view
C:\o\mysite\pet\views.py in Profile
60. return render_to_response('profile.html', {'Person': Person}, context_instance=RequestContext(request))
問題是鏈接到我的個人資料功能在views.py
我的我的views.py
@login_required
def Profile(request):
if not request.user.is_authenticated():
return HttpResponseRedirect('/login/')
Person = request.user.get_profile
return render_to_response('profile.html', {'Person': Person}, context_instance=RequestContext(request))
我profile.html
{% if Person %}
<ul>
<li>Name : {{Person.user}} </li>
</ul>
{% endif %}
我的模型零件.py
from django.db import models
from django.db.models.signals import post_save
from django.contrib.auth.models import User
class Person(models.Model):
user = models.OneToOneField(User)
name = models.CharField(max_length=100)
image = models.FileField(upload_to="images/",blank=True,null=True)
def __unicode__(self):
return self.name
class Pet(models.Model):
Person = models.ForeignKey(Person)
description = models.CharField(max_length=100)
image = models.FileField(upload_to="images/",blank=True,null=True)
def __unicode__(self):
return self.description
'人 - request.user.get_profile'應該是'人= request.user.get_profile()' – 2013-03-08 10:13:31
是啊,我仍然得到錯誤 – donkeyboy72 2013-03-08 10:15:29
它; s代碼的排列 – catherine 2013-03-08 10:16:19