Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Django错误局部变量';人';分配前参考_Django - Fatal编程技术网

Django错误局部变量';人';分配前参考

Django错误局部变量';人';分配前参考,django,Django,我正在尝试制作一个应用程序,让宠物的主人可以创建自己的个人资料并上传宠物的照片 当用户创建帐户或登录时,他会被重定向到配置文件中。个人资料页面应显示他的信息,例如姓名,而不是我收到此错误 UnboundLocalError at /profile/ local variable 'Person' referenced before assignment Request Method: GET Request URL: /profile/ Django Version: 1.4.3 Exce

我正在尝试制作一个应用程序,让宠物的主人可以创建自己的个人资料并上传宠物的照片

当用户创建帐户或登录时,他会被重定向到配置文件中。个人资料页面应显示他的信息,例如姓名,而不是我收到此错误

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上的my Profile函数

我的部分视图.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))
My profile.html

{% if Person %}
<ul>
        <li>Name : {{Person.user}} </li>
</ul>
{% endif %}     

尝试将Person置于request.user.is\u的顶部。你忘了在get_档案里写“()”

@login_required     
def Profile(request):
    Person = request.user.get_profile()
    if not request.user.is_authenticated():
        return HttpResponseRedirect('/login/')
    return render_to_response('profile.html', {
        'Person': Person
     }, context_instance=RequestContext(request))

Person-request.user.get\u profile
应该是
Person=request.user.get\u profile();s您的代码安排
def配置文件(请求):
在您的
型号中。py
也不正确。在我看来,它应该存在于
url.py
@limelights中感谢您的帮助,我必须将它复制到错误的位置!谢谢:,赋值前引用的局部变量“Person”是什么意思?您呈现了一个空Person变量。如果你呈现一个变量,你必须检查你是否正确调用它并定义它。我认为你呈现null Person是因为你忘了在get_profile中输入“()”,结果没有数据。谢谢你,凯西,你的英雄:]
@login_required     
def Profile(request):
    Person = request.user.get_profile()
    if not request.user.is_authenticated():
        return HttpResponseRedirect('/login/')
    return render_to_response('profile.html', {
        'Person': Person
     }, context_instance=RequestContext(request))