-
Notifications
You must be signed in to change notification settings - Fork 128
Built in views
Dave Hall edited this page Aug 29, 2011
·
7 revisions
django-watson comes with a built-in search view to make building a site-wide search easy.
To use it, add the django-watson urls to your site's urlconf:
url(r"^search/", include("watson.urls", namespace="watson"))
You can then perform a search by including a form in your template as follows:
<form action="{% url 'watson:search' %">
<input name="q" value="{{request.GET.q}}">
<input type="submit" value="Go">
</form>
The built-in search view will display a list of results taken from your site-wide set of registered models. You can customize the way it renders as follows:
- query_param: The GET parameter to use for the search term (default 'q').
- template_name: The name of the template used to render the search results (default 'watson/search_results.html')
- empty_query_redirect: The page to redirect to if the user enters an empty search term (default None)
- models: The list of models to search from (default all)
- exclude: The list of models to exclude from search results (default none)