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

175
Views
Django form in a base class

forms.py

class search_form(forms.Form):
    options = categories.objects.all()
    category = forms.ModelChoiceField(options, initial={'All':'All'}, label='')
    search = forms.CharField(max_length=100, label='', required=False)

This form is used for searching for items. And right now I have it implemented on the index page and it works as expected. The index (home) page has its own view that makes use of this form, but I have a base template (base.html) that every page on the site extends. The base template holds the menu bar and the footer of the site. I need to add the form to the base class and have it function in every template that extends it.

Is there a way to do this?

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

You can add a custom context processor, which is useful for passing data to every template context, which will give every template access to your form.

As explained in the docs, you need to make a function that will return a dictionary containing your form, and point to it in the settings.

over 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!