I am developing a site in Django and having two types of profiles. One of them named Person. So I am trying to access a Person object, using following code:
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)
And it gives error:
DoesNotExist at /p/Haafiz/
UserProfile matching query does not exist.
At another place, I am trying to do so with following code:
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)
And in this case, it is working fine. What can be problem at first place where I am trying to access profile from object getting from db? Both these cases seems same to me but it is having problem in the above one.