How can I return the input of the API request into my html template, without it returning on my terminal using Django?
this is my function that uses google finance api to get news articles.
someapp/views.py
def news(request):
if request.method == 'POST':
url = "https://google-finance4.p.rapidapi.com/ticker/"
querystring = {"t":"ETH-USD","hl":"en","gl":"US"}
headers = {
"X-RapidAPI-Key": "API KEY",
"X-RapidAPI-Host": "google-finance4.p.rapidapi.com"
}
response = requests.request("GET", url, headers=headers, params=querystring)
response.status_code
response.text
response.json()
articles = response.json()['news']
return render(request, 'news.html', {
"article": articles })
else:
return HttpResponse('Error')
this is the html code
<body class="bg-dark">
<div
style="
position: flex;
width: 450px;
align-items: center;
align-content: center;
justify-content: center;
margin: 370px auto;
"
>
<img class ="img-fluid" src="{% load static %} /static/logo.png" "
alt="Crypto Talk"
</div>
<p>**{{ article }}**</p>
</body>
this is the html to the page where the POST request is coming from.
<form
class="form-inline"
method="POST"
action="{{ 'news/' }}"
name="news"
>
<div
class="input-group mb-3"
style="margin: 0 auto; display: flex; width: 450px"
>
{%csrf_token%}
<input
type="text"
class="form-control"
placeholder="Enter Crypto"
name="search"
style="
display: block;
margin: 0 auto;
border-top-left-radius: 0;
border-bottom-right-radius: 0;
border-top-left-radius: 5px;
border-bottom-left-radius: 5px;
"
/>
<button
class="btn btn-outline-primary btn-md"
type="submit"
id="button-addon2"
>
Search
</button>
for some reason it takes me to the new html but the page only has the logo. The content from the api I am looking to return is showing up in my terminal with the error "Not Found: /news/requestProvider.js.map"? is there something wrong with how im using Django's templating language or does it have to do with my views? Ultimately I am trying to render the articles found in the 'news' key when using this api and rendering it just like a google search.
Just needed to change the text color! hahaha.