[Fixed]-How Do I create a search that works in all my views in Django

1👍

I think it could be pretty easy. Just give search a dedicated view function and a corresponding url, let’s say:

url(r'^post-search/$', views.post_search, name='post-search')

Then you put your current search form in base.html, with a change in form’s action pointing to the post-search url:

<form method="GET" action="{% url 'post-search' %}"  class="navbar-form navbar-right">
    <!-- same content goes here -->
</form>

So now every time you submit this form, it would always go to execute the view function post_search and you do the same process and show the result.

Some explanations about form action attribute.

Leave a comment