Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7753273
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T12:01:05+00:00 2026-06-01T12:01:05+00:00

I am conditionally using two different url patterns, mean on one URL I am

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T12:01:06+00:00Added an answer on June 1, 2026 at 12:01 pm

    No code in Python ever has automatic access to variables defined elsewhere. Names must always either be defined within the current module, or imported from elsewhere. This applies to the request as much as to any other Python variable.

    However, even if you were able to get a request variable into urls.py, this still would not work. URLconfs are general to the whole server process, not specific to each request. There’s simply no such thing as “the request” or “the user” at the point when the urls are evaluated.

    The correct way to do this is to define a simple view for dashboard that just checks request.user and then dispatches to the correct function from there.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How can I use JavaScript to display one of two different layouts based on
I'm building a carArray and want to filter the contents conditionally, using an NSPredicate
I've come across two different ways to define/name objects and functions in JavaScript that
While looking for something totally different the other day, I have stumbled upon two
I'm using two regular expressions to pull assignments out of MySQL queries and using
I have a need to reference two different versions of the Sharepoint API dll.
I code C++ using MS Dev Studio and I work from home two days
Using VS2008 TFS I have created a setup application that installs two Window Services.
Is it possible to link conditionally(like an if..else) by using the linker command file?
I have a servlet which can accept upwards of two dozen different kinds of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.