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 367199
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T13:42:19+00:00 2026-05-12T13:42:19+00:00

I have two different kinds of objects that I’d like to live under the

  • 0

I have two different kinds of objects that I’d like to live under the same URL. One group of objects needs to be passed to the view function ‘foo’ and another group needs to be passed to ‘bar’.

I’m currently doing this with a big long list of hardcoded URLs, like so…

urlpatterns = patterns('project.views',
    (r'^a/$', 'foo'),
    (r'^b/$', 'foo'),
    (r'^c/$', 'foo'),
    #...and so on until...
    (r'^x/$', 'bar'),
    (r'^y/$', 'bar'),
    (r'^z/$', 'bar'),
)

Is it possible to define a list of each type of URLs like…

foo_urls = ['a', 'b', 'c'] #...
bar_urls = ['x', 'y', 'z'] #...

…and then check the incoming URL against those lists? (If it’s in ‘foo_urls’, send to ‘project.views.foo’; if it’s in ‘bar_urls’, send to ‘project.views.bar’)?

I’m limited to keeping this structure to maintain compatibility with the URLs from the previous site, but any advice on ways to simplify my urls.py would be much appreciated.

  • 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-05-12T13:42:19+00:00Added an answer on May 12, 2026 at 1:42 pm

    The url maps are usually expressed explicitly, but they don’t have to be. How about building your URL map from your lists?

    foo_urls = ['a', 'b', 'c'] #...
    bar_urls = ['x', 'y', 'z'] #...
    
    # A first pattern to get urlpatterns started.
    urlpatterns = pattern('project.views', 
        ('blah', 'blah')
        )
    
    # Append all the foo urls.
    for foo_url in foo_urls:
        urlpatterns += patterns('project.views',
            ('^' + foo_url + '/$', 'foo')
            )
    
    # Append all the bar urls.
    for bar_url in bar_urls:
        urlpatterns += patterns('project.views',
            ('^' + bar_url + '/$', 'bar')
            )
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two different libGL libraries on the same Ubuntu 11.04 machine. One library
I have two vector objects that contain different types of data that are ordered
I have two different kinds of objects: Ride and Location . A Ride has
I have two lists of two different kinds of objects representing data rows from
Is this possible to have two (or more) different kinds of cells to be
I have two different arrays, one with strings and another with ints. I want
I have two different tables, lead and click. I would like to query MySQL
I am working on an ASPX page that needs to handle multiple different kinds
I have a selectOneMenu that manages a relation between two Objects A and B.
In my specific case, I have two kinds of messages that I need to

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.