I am conditionally using two different url patterns, mean on one URL I am conditionally checking usertype and then making URL pattern accordingly.Following is what that is in my urls.py
from django.conf.urls.defaults import *
from project import settings
from accounts.models import UserProfile
profile=request.user.get_profile()
urlpatterns=patterns('accounts.views',
(r'^register/$','register',{'template_name':'accounts/ register.html'},'register'),
)
try:
profile.profile1
urlpatterns+=patterns("profile1.views",
(r'^dashboard/$','dashboard'),
)
except UserProfile.DoesNotExist:
urlpatterns+=patterns("profile2.views",
(r'^dashboard/$','dashboard'),
)
urlpatterns+=patterns('django.contrib.auth.views',
(r'^login/$','login',{'template_name':'account/login.html'},'login'),
)
Now when I tried to get user profile by using request.user.get_profile
then django says request is not defined. It is true but how can I get this profile defined till that place by using some import or there is some other better way to do such thing?