[Fixed]-Passing form input data to post request

1👍

from django import SearchForm
ImportError: cannot import name ‘SearchForm’

The updated error is because you are trying to import the SearchFrom from the root of the django library.

You need to import your SearchForm from your app, so in your views.py

from django import SearchForm

should be something like

from myapp.form import SearchForm

Also, in Django it is common to call your forms containing file forms(plural) instead of form (singular), since it can contain multiple forms.

0👍

The SearchForm is in your django app and not in your django library.

Use from .form import SearchForm

Also, move your else to ( if request.method == POST ), so that the form is sent if method is not post.

And I would suggest you to use reverse() function to resolve url ,

HttpResponseRedirect(reverse(‘search’))

Leave a comment