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.
-
@I have edited the code of views.pymathers25– mathers252017-07-08 06:44:02 +00:00Commented Jul 8, 2017 at 6:44
Add a comment
|
2 Answers
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.
4 Comments
mathers25
sorry,I Posted the unedited version of views.py.I have already tried "data=request.GET.get('Location')"..It doesn't work
neverwalkaloner
@mathers25 oh I missed
return statement in you code. Try to move it at the end of function.mathers25
Thanks man!It worked.One more thing..if i want to pass this value to a url to make an api call should i do that in views.py ?
neverwalkaloner
@mathers25 you are welcome! Sure you can pass in in view as url argument using reverse fuction:
reverse('url', args=[data]) or you can add it to the url as GET arguments: `{0}?data={1}'.format(reverse('url'), data). You can find details about reverse function here: docs.djangoproject.com/en/1.11/ref/urlresolvers/#reverse