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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T01:13:05+00:00 2026-06-09T01:13:05+00:00

I want to use the same template to display records from different models in

  • 0

I want to use the same template to display records from different models in django, with generic class viewers. The generic class viewers already accept most of the arguments needed in the template, except for one.

How can I pass this extra argument in the context to the template?

I have tried passing it as the third (extra) argument in the urlconf, without success:

# in urlconf.py
url(r'^processador/(?P<pk>[\w-]+)/$',
    UpdateView.as_view(
        model=Processador,
        template_name='model_form.html',
        success_url=reverse_lazy('processador-list'),
        ),
    {'extrainfo': "Processador"},
    name='processador-detail'
),

url(r'^software/(?P<pk>[\w-]+)/$',
    UpdateView.as_view(
        model=Software,
        template_name='model_form.html',
        success_url=reverse_lazy('software-list'),
        ),
    {'extrainfo': "Software"},
    name='software-detail'
),

There will be several urlconfs like these in my application.

One possibility is sub-classing the view class and provide my own implementation of the get_context_data method which add the desired key-value pair.

But this solution is too repetitive, as it would be applied to every use of the view class.

Maybe it is possible to make only one subclass of the view class. The as_view class method in this new class would accept a new named argument which would go into the context in the redefinition of get_context_data.

I am not too experienced in django and Python, so I am not sure how to accomplish this and I am accepting help.

  • 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-06-09T01:13:06+00:00Added an answer on June 9, 2026 at 1:13 am

    I think you can do this with only one subclass of UpdateView, rather than the one per model that I think you think you need.

    Arguments to as_view get set as attributes on the object which is returned, so I think you could do

    class MyUpdateView(UpdateView):
        extrainfo = None
    
        def get_context_data(self, **kwargs):
            context = super(MyUpdateView, self).get_context_data(self, **kwargs)
            context['extrainfo'] = self.extrainfo
    
            return context
    

    And then call this in your urlconf like

    url(r'^processador/(?P<pk>[\w-]+)/$',
        MyUpdateView.as_view(
            model=Processador,
            template_name='model_form.html',
            success_url=reverse_lazy('processador-list'),
            extrainfo="Processador"
            ),
        name='processador-detail'
    )
    

    I’m not at all sure you should do this though – it’s heading towards too much stuff in the urls.py.

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

Sidebar

Related Questions

I want to use the same {% block %} twice in the same django
I want to use the same ant script to do a build in either
I want to use the same style in many listviews. And in my style
i have a variable $cartTotal in cart.php page i want to use that same
I want to use regular expression same way as string.Format. I will explain I
i want to use focus function in jquery to return to same area of
I want to be able to use the mapfield in the same manner as
Attention advanced Freemarker gurus: I want to use a single freemarker template to be
I have 5 game sections that will use the same template sheet, but they
I want to re-use a template I have with my WTForms form: <th>${form.name.label}</th> <td>${form.name()}</td>

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.