For the Wiki project I'm having trouble implementing the search bar. I have spent about 2 days researching search bars in Django, but so far everything I've tried yields the same result:

No matter what I try, when I search for an article name that exists, the homepage just stays exactly the same, but only the URL changes to So for example, everything after the ?q= is the title of the article (this one is called Apple). But the page I'm on stays the same and doesn't go to the actual page I'm looking for. I'm wondering if the url is part of the problem because I know other search bars have the end of the url looking like: Search?q=Apple

urlpatterns = [
path("", views.index, name="index"),
path("wiki/<str:title>", views.entry, name="entry"),
path("search", views.search, name="search"),

If the query matches the title of an article entry, the user should be redirected to that entry’s page. Here is one of the examples I tried and all code associated in views.py:




Nevermind, I have been able to figure it out. I had to use a GET request.

0 is not the URL you should redirect the query. Use instead.

So, in your form you should have something like this:

<form action="{% url 'search' %}" method="get">

Also, set the search path before the entry path, in your urls.py:

path("search", views.search, name="search"), path("wiki/<str:title>", views.entry, name="entry"),

Hope this help

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .