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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T19:15:29+00:00 2026-05-10T19:15:29+00:00

I have a Django model with a large number of fields and 20000+ table

  • 0

I have a Django model with a large number of fields and 20000+ table rows. To facilitate human readable URLs and the ability to break down the large list into arbitrary sublists, I would like to have a URL that looks like this:

/browse/<name1>/<value1>/<name2>/<value2>/ .... etc .... 

where ‘name’ maps to a model attribute and ‘value’ is the search criteria for that attribute. Each ‘name’ will be treated like a category to return subsets of the model instances where the categories match.

Now, this could be handled with GET parameters, but I prefer more readable URLs for both the user’s sake and the search engines. These URLs subsets will be embedded on each page that displays this model, so it seems worth the effort to make pretty URLs.

Ideally each name/value pair will be passed to the view function as a parameter named name1, name2, etc. However, I don’t believe it’s possible to defined named patterns via a regex’s matched text. Am I wrong there?

So, it seems I need to do something like this:

urlpatterns = patterns('',     url(r'^browse/(?:([\w]+)/([\w]+)/)+$', 'app.views.view', name='model_browse'), ) 

It seems this should match any sets of two name/value pairs. While it matches it successfully, it only passes the last name/value pair as parameters to the view function. My guess is that each match is overwriting the previous match. Under the guess that the containing (?:…)+ is causing it, I tried a simple repeating pattern instead:

urlpatterns = patterns('',     url(r'^browse/([\w]+/)+$', 'app.views.view', name='model_browse'), ) 

… and got the same problem, but this time *args only includes the last matched pattern.

Is this a limitation of Django’s url dispatcher, and/or Python’s regex support? It seems either of these methods should work. Is there a way to achieve this without hardcoding each possible model attribute in the URL as an optional (.*) pattern?

  • 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. 2026-05-10T19:15:30+00:00Added an answer on May 10, 2026 at 7:15 pm

    A possibility that you might consider is matching the entire string of possible values within the url pattern portion and pull out the specific pieces within your view. As an example:

    urlpatterns = patterns('',     url(r'^browse/(?P<match>.+)/$', 'app.views.view', name='model_browse'), )  def view(request, match):     pieces = match.split('/')     # even indexed pieces are the names, odd are values     ... 

    No promises about the regexp I used, but I think you understand what I mean.

    (Edited to try and fix the regexp.)

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

Sidebar

Related Questions

I have Django Model with many fields which user must fill. If I'll create
I have a Django model with some fields that have default values specified. I
I have Django model and in one of the fields I need to store
Say I have django model that looks something like this: class Order(models.Model): number =
I have this Django model: class Lecture(models.Model): lecture_number = models.CharField(_('lecture number'), max_length=20) title =
I have django models such as this class District(models.Model): name = models.CharField(max_length=30,unique=True) number =
I have django model which consist of parent child relationship filed I want to
I have a Django model TimeThingie with two TimeField s called t1 and t2
I have a Django model with separate Datefield and Timefield for an event. Is
I have a Django model which has a foreign key that is optional. I

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.