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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T21:16:52+00:00 2026-06-01T21:16:52+00:00

I have a web site on Django. I want to create a search input

  • 0

I have a web site on Django.
I want to create a search input on every page.
In some “base.html” I write new for this search input.

In views.py I add something like:

def main(request):
    if request.method == 'POST':
        search_string = request.POST['search_string']
        result = search(search_string)
        return direct_to_template(request, 'found_page.html', {'result': result})`

But I want it on EVERY page.

So, I create new function “search_function(request)” and add it to EVERY def in views.py.
Or I can create a decorator and write it before EVERY def in views.py.

I don’t want to do it EVERY time I add new def.
But I don’t know how.
Need your 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-01T21:16:53+00:00Added an answer on June 1, 2026 at 9:16 pm

    So this is what I think you want to do: display a search input form on every page (whichever applicable), and use only one views to handle the search.

    1. create one view that handles search
    2. create a html page that has the <form> element of the search whose action goes to your views done in the previous step
    3. include or extend it in your base.html

    What I don’t get is, do you need the search happen to be the search on the local page? (for example, search within this forum)

    To get the query you can just supply the query by request.GET['q'] or request.POST['q'] or similar.

    def search(request):
      if 'q' in request.GET and request.GET['q']:
         // do something
    

    Unless your search (query) changes the state of the query result in the database, you don’t want to use POST. Use GET instead.

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

Sidebar

Related Questions

I have some Django websites and I want to place them on the webserver
I am currently trying to create a REST web service for my django site
I'm using Django to create a site that provides a separate web UI for
I have some sections on my web site where only logged in users can
I'm new in django and python. I want to have a form in one
I am a new guy in a web development. I have some experience with
I'm new to both Django and Cappuccino. I have a Django site setup and
I've been developing a web-site that uses Django and MySQL; what I want to
I have a Django website in which I want site administrators to be able
I want to create a website for students with django. I have learning_plan with

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.