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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T21:57:46+00:00 2026-05-16T21:57:46+00:00

I have the following model and url routes. There is one Post model that

  • 0

I have the following model and url routes. There is one Post model that I want to route to different URLs based on the category. Is there a way to do this by passing in extra information in app/urls.py?

In app/posts/models.py

class Post(models.Model):
    author = ...
    title = ...
    body = ...
    category = models.CharField()

In app/urls.py

urlpatterns = patterns(
    '',
    (r'^blog/', include('posts.urls'), {'category': 'blog'}),
    (r'^school/', include('posts.urls'), {'category': 'school'}),
)

My understanding is that the extra info from app/urls.py is included in each url route in app/posts/urls.py. Is there a way to use that information? What can I put in place of the exclamation points below?

In app/posts/urls.py

from models import Post

queryset = Post.objects.order_by('-pub_date')

urlpatterns = patterns(
    'django.views.generic.list_detail',
    url(r'^$', 'object_list',
        {'queryset': queryset.filter(category=!!!!!!)}
        name="postRoot"),

    url(r'^(?P<slug>[-\w]+)/$', 'object_detail',
        {'queryset': queryset.filter(category=!!!!!!)},
        name="postDetail")
    )

Thanks, joe

  • 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-16T21:57:46+00:00Added an answer on May 16, 2026 at 9:57 pm

    I am not aware of a way to use the URL parameters the way you have indicated. If anyone knows better, do correct me.

    I faced a similar situation some time ago and made do with a thin wrapper over the list_detail view.

    # views.py
    from django.views.generic.list_detail import object_list
    
    def object_list_wrapper(*args, **kwargs):
        category = kwargs.pop('category')
        queryset = Post.objects.filter(category = category)
        kwargs['queryset'] = queryset
        return object_list(*args, **kwargs)
    
    #urls.py
    urlpatterns = patterns('myapp.views',
        url(r'^$', 'object_list_wrapper', {}, name="postRoot"),        
    ...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a simple url that will toggle one field in my search model.
I have the following Model and Controller files, and when i visit this url,
I have a project that can be accessed at the URL: myapp.com/project/my-project Route To
I have the following code: Url.Action(Index, Home, new {param1 = Model.Param1, param2 = Model.Param2}
I have the following routes defined in my global.asax: routes.MapRoute( Agreements2, // Route name
I am having problems with Html.ActionLink when I have a route that takes one
I have the following model in my view that I am passing to it:
I have the following model: public class Contact { public Contact() { Name =
I have the following model: public class Tag { public int Id { get;
I have the following model: WebPromocion: connection: doctrine tableName: WebPromocion columns: id: type: integer(4)

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.