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

  • Home
  • SEARCH
  • 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 507199
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T06:46:46+00:00 2026-05-13T06:46:46+00:00

This seems like it should be obvious, but the solution is eluding me. Normally

  • 0

This seems like it should be obvious, but the solution is eluding me. Normally I would just write a simple view function which would populate an appropriate form and pass it along to the view, but the solution feels so close ..

I have a form. I want to instantiate this form using an object_id that I’ve captured in the url, then send it through to my template using the extra_context parameter.

I have something like this:

class AddProductForm(forms.Form): 
    product = forms.IntegerField()
    quantity = forms.IntegerField()

and this:

url(r'^products/(?P<object_id>\d+)/$', 
    'django.views.generic.list_detail.object_detail',
    {'queryset': Product.objects.all(),
    'extra_context': {'form': AddProductForm({'product': <what?>, 'quantity': 1})},
    name='product_detail'),

Is there a way to replace <what?> above with the captured value of object_id? (Maybe a clever callable passed in extra_context could make the form for me?)

  • 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-13T06:46:47+00:00Added an answer on May 13, 2026 at 6:46 am

    I’m afraid you can’t do that in your urlconf. Any callables you supply can not accept any arguments, so you won’t be able to get the value of ?P<object_id>.

    You can however re-use the generic view in your own view to cut down on the amount of boilerplate you have to write:

    from django.views.generic.list_detail import object_details
    from your.forms import AddProductForm
    from your.models import Product
    
    def about_pages(request, object_id=None):
        qs = Product.objects.all()
        f = AddProductForm({'product':object_id,'quantity':1})
        return object_details(request,queryset=qs,extra_context={'form':f},template='yourtemplate.html')
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This seems like it should be prettty easy - but I just can't get
This seems like it should be pretty obvious, but I've tried substitute , bquote
This seems like something that should be painfully obvious, but for whatever reason I
It seems like this should be straightforward but I'm boggling. I've got my listview
First check out this code. I seems like it should work for me, but
This seems like a simple question, but I can't find it with the Stack
This seems like a silly question but I would really like your comments and
This seems like it should be so easy, but I've tried three or four
Seems like this should be easy or at least documented somewhere, I just cant
It seems like there should be something shorter than this: private string LoadFromFile(string path)

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.