Search code examples
pythondjangoweb-frameworks

Fetch Data from html form to use it in views.py-Django


I am new to django so bear with me.I am trying to build a simple web app to fetch the current weather.Problem is I am not able to fetch the pincode entered in my HTML form and use it in my views.py file. As I told u I am new to django so please try to explain it the most simple way. Thanks.enter image description here

enter image description here


Solution

  • Your form has GET method, but in view you are trying to fetch data from POST. Change view code to this:

    data=request.GET.get('Location')
    

    Also you shoul move

    return HttpResponse('hello')
    

    at the end of view. Code after return will never be called.