I've been working on Project 1 from CS50W for a few days now and finally got my search bar to appear on my page! The issue I have now is I don't think the input is being pulled in from my form. I've tried inserting print() statements but they aren't printing anything to the terminal.


class SearchForm(forms.Form):
    search = forms.CharField(max_length=100, label='', widget=forms.TextInput(attrs={
        "placeholder": "Search Encyclopedia",
        "id": "q",
        "class": "search"


def search(request):
    form = SearchForm()
    if request.method == 'POST':
        form = SearchForm(request.POST)
        if form.is_valid():
            searchTerm = form.cleaned_data['q']
            return HttpResponseRedirect(reverse("wiki:entries", searchTerm))


<form action="{% url 'wiki:search' %}" method="POST">
    {% csrf_token %}
    {{ form }}

I feel like I might be missing something obvious but I've looked through the documentation and watched a few videos and I think it looks like it should work but I've clearly missed something. Any help is appreciated!


So my issue had nothing to do with any of the code I posted above. The problem was in my urls.py, after my index page, the next path was path("<str:title>", entries, name="entry")which meant any page I tried to visit was being treated as an entry in the encyclopedia.

Moving this path so it appears last in the list makes sure that it doesn't interfere.

You must log in to answer this question.

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