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
Can';t在数据库中通过查询访问Django配置文件,同时获取登录用户的配置文件_Django_Django Models_Django Profiles - Fatal编程技术网

Can';t在数据库中通过查询访问Django配置文件,同时获取登录用户的配置文件

Can';t在数据库中通过查询访问Django配置文件,同时获取登录用户的配置文件,django,django-models,django-profiles,Django,Django Models,Django Profiles,我正在Django开发一个站点,有两种类型的配置文件。其中一个叫佩森。因此,我尝试使用以下代码访问Person对象: from django.contrib.auth.forms import UserCreationForm from django.template import RequestContext from django.shortcuts import render_to_response,get_object_or_404 from django.core import url

我正在Django开发一个站点,有两种类型的配置文件。其中一个叫佩森。因此,我尝试使用以下代码访问Person对象:

from django.contrib.auth.forms import UserCreationForm
from django.template import RequestContext
from django.shortcuts import render_to_response,get_object_or_404
from django.core import urlresolvers
from django.http import HttpResponseRedirect
from django.contrib.auth.decorators import login_required
from accounts.forms import UserRegistrationForm, UserProfileForm
from pprint import pprint
from django.http import HttpResponse
from  models import User
from models import UserProfile

def profile(request, url,template_name='person/profile.html'):
    user=User(username=url).get_profile().person;
    return HttpResponse(user)
from django.contrib.auth.forms import UserCreationForm
from django.template import RequestContext
from django.shortcuts import render_to_response,get_object_or_404
from django.core import urlresolvers
from django.http import HttpResponseRedirect
from django.contrib.auth.decorators import login_required
from accounts.forms import UserRegistrationForm, UserProfileForm
from pprint import pprint
from django.http import HttpResponse
from accounts.forms import UserProfile

@login_required
def dashboard(request,template_name="account/dashboard.html"):
    return HttpResponse(request.user.get_profile().person)
它给出了一个错误:

DoesNotExist at /p/Haafiz/
UserProfile matching query does not exist.
在另一个地方,我尝试使用以下代码来实现:

from django.contrib.auth.forms import UserCreationForm
from django.template import RequestContext
from django.shortcuts import render_to_response,get_object_or_404
from django.core import urlresolvers
from django.http import HttpResponseRedirect
from django.contrib.auth.decorators import login_required
from accounts.forms import UserRegistrationForm, UserProfileForm
from pprint import pprint
from django.http import HttpResponse
from  models import User
from models import UserProfile

def profile(request, url,template_name='person/profile.html'):
    user=User(username=url).get_profile().person;
    return HttpResponse(user)
from django.contrib.auth.forms import UserCreationForm
from django.template import RequestContext
from django.shortcuts import render_to_response,get_object_or_404
from django.core import urlresolvers
from django.http import HttpResponseRedirect
from django.contrib.auth.decorators import login_required
from accounts.forms import UserRegistrationForm, UserProfileForm
from pprint import pprint
from django.http import HttpResponse
from accounts.forms import UserProfile

@login_required
def dashboard(request,template_name="account/dashboard.html"):
    return HttpResponse(request.user.get_profile().person)
在这种情况下,它运行良好。在我试图从db获取的对象访问概要文件的第一个地方,会出现什么问题?这两种情况在我看来都是一样的,但在上面的一种情况中存在问题。

User(name=url)
只生成一个User实例,而不是为某个用户查询数据库

改变

user=User(username=url).get_profile().person


请分享你的模型。。。现在是gesswork如何查询
Person
模型对象。