Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

312
Views
Django ContextMixin objeto 'super' no tiene atributo 'get_context_data'

Necesito pasar algo de contexto a las plantillas en varias vistas. El contexto se obtiene de la BD utilizando la información de algunos usuarios, por lo que implementé una clase ContextMixin específica:

 class CampaignContextMixin(ContextMixin): """ This mixin returns context with info related to user's campaign. It can be used in any view that needs campaign-related info to a template. """ def get_campaigns(self): # Get the first campaign related to user, can be more in the future return self.request.user.campaign_set.all() # Method Overwritten to pass campaign data to template context def get_context_data(self, **kwargs): context = super(CampaignContextMixin).get_context_data(**kwargs) campaign = self.get_campaigns()[0] context['campaign_name'] = campaign.name context['campaign_start_date'] = campaign.start_date context['campaign_end_date'] = campaign.end_date context['org_name'] = self.request.user.organization.name context['campaign_image'] = campaign.image.url context['campaign_details'] = campaign.details return context

Luego estoy tratando de usarlo en mis vistas, pero recibo un error:

El objeto 'super' no tiene atributo 'get_context_data'

 class VoucherExchangeView(CampaignContextMixin, TemplateView): """ This view Handles the exchange of vouchers. """ template_name = "voucher_exchange.html" def get_context_data(self, **kwargs): ctx = super(VoucherExchangeView).get_context_data(**kwargs) # add specific stuff if needed return ctx

No estoy seguro si se debe a un error de herencia o porque TemplateView hereda también de ContextMixin. Mi objetivo es reutilizar el código que agrega la información de las campañas al contexto.

Gracias

about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Querías decir

 super(CampaignContextMixin, self).get_context_data(**kwargs) #super().get_context_data(**kwargs) --> python3
about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!