I am trying to create a simple django site that would send information to another site with the
requests.post function (I'm assuming that this is a correct method, but maybe there is a better way).
So far I have a simple .html file created using bootstrap
<div class="form-group">
<label for="exampleFormControlInput1">text_thing</label>
<input type="text" class="form-control" placeholder="text_thing" name="text_thing">
</div>
<div class="form-group">
<label for="exampleFormControlInput1">number_thing</label>
<input type="number" class="form-control" placeholder="number_thing" name="number_thing">
</div>
<button type="submit" class="btn btn-secondary">Send data</button>
</form>
and my views.py
from django.shortcuts import render, redirect
import requests
def my_view(requests):
if requests.method == "POST":
text_thing= request.GET.get('text_thing')
number_thing= request.GET.get('number_thing')
post_data = {'text_thing', 'number_thing'}
if text_thing is not None:
response = requests.post('https://example.com', data=post_data)
content = reponse.content
return redirect('home')
else:
return redirect('home')
else:
return render(requests, 'my_view.html', {})
I want the site to do following: render itself allowing the user to input something in both fields, and after pressing the button to be redirected to another site - in this case 'home' and for the input to get sent to example.com. With this moment the page renders correctly but after pressing the button nothing happens and external site receives no data.
You have a couple of errors in your code that needs to be fixed first
if your site is not receiving any data, check the response from that other site, to make sure you are calling the right API.
I hope this helped