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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T19:31:22+00:00 2026-05-13T19:31:22+00:00

I want to be able to pass a variable caught in the URL to

  • 0

I want to be able to pass a variable caught in the URL to a Q object for a generic view.

I created a generic view which is imported as my_views.view which handles things like pagination, sorting, filtering etc…

I need to use Q objects because for some pages there will need some OR filters. Each page will also be filtering based on different fields (and models) (hence the generic view).

Example:

view_customers_info = {
    "queryset" : Customer.all(),
    'qobject': Q(status=stat),
    "extra_context" : {
        "title" : 'View Customers',
    },
    'template_name': 'customer/view.html',
}
urlpatterns = patterns('',
  url(r'^customer/(?P<stat>\w+)/$', my_views.view, view_customers_info),
)

In this example, this line complains about stat not being a global name:

'qobject': Q(status=stat),

How can I pass the variable caught in the URL to the dictionary view_customers_info?

I can’t simply move that Q object into the generic view because other pages will have Q objects like the following:

'qobject': (Q(type=type) | Q(status=stat)),

Thanks.

  • 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-13T19:31:22+00:00Added an answer on May 13, 2026 at 7:31 pm

    I think you can only do this by wrapping the generic view with a custom view/function. See also here:

    http://docs.djangoproject.com/en/1.1/topics/generic-views/#complex-filtering-with-wrapper-functions

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

Sidebar

Related Questions

I am able to pass a variable forward from view controller to view controller
I want to be able to pass a variable type to a method, mainly
I'm not able to pass a simple variable to the view , can someone
I want to be able to pass in my actual parsing function in my
I want to be able to pass in the path of a folder to
I want to be able to pass fields into the edit form when a
I want to be able to pass anything to a git command (maybe its
I want to be able to pass a string (['parent_array']['child_array']) to a function that
I have an web address: http://www.example.com/org/companyA I want to be able to pass CompanyA
Hey guys I am not able to pass the variable profile through... This is

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.