Index.html not showing data

Asked by : melany wijngaard 2020-04-02 13:35

This is a simple project but I am stock somehow. I am trying to create my own webhooks receiver server that shows received data in index.html at '/' when a webhook is received using '/webhook'. Technically, I just want the flask to show the last data received at '/webhook' using 'index.html' at '/' but it doesn't work.

Here's my flask directory:

Here's my code:

 from flask import Flask, render_template, request, abort, json, redirect, url_for

app = Flask(__name__)

def hello():
    title = request.args.get('title', None)
    jsonfile = request.args.get('jsonfile', None)
    print("Recieved:", title, jsonfile, type(jsonfile)) 
    return render_template('index.html', title=title, jsonfile=jsonfile)

@app.route('/webhook', methods=['POST'])
def webhook():
    if request.method == 'POST':
        data = request.json       
        return redirect(url_for('hello', title='Result', jsonfile=data)), 'success', 200

if __name__ == '__main__':

Here's my

 import requests,json

webhook_url = "http://localhost:5000/webhook"

data = {
    'fn_name': 'abc',
    'last_name': 'xyz'

r =
    webhook_url, data=json.dumps(data),
        'Content-Type': 'application/json'

And here's my index.html:

 <!DOCTYPE html>
    <meta charset="UTF-8" />
    <title>{{ title }}</title>
    {{ jsonfile }}

I get this when I send webhook. - - [26/Jan/2022 12:00:39] "POST /webhook HTTP/1.1" 500 -


TypeError: 'int' object is not iterable

Let me know what you think.

1 Answers

0 votes
giselle monteiro
Answer by : giselle monteiro

You placed these outside of the function, so it was trying to return all three and didn't know what to do with the "200":

 return redirect(url_for('hello', title='Result', jsonfile=data)), 'success', 200

Not sure if "success" and "200" are valid arguments to the redirect function but the desired result can be achieved with:

 return redirect(url_for('hello', title='Result', jsonfile=data))

Related Posts
Related Posts
ANGULAR push element in formArray no ren...
نيما جعفری نيما جعفری
2020-02-01  4:27pm 2020-02-01 4:27pm
Move multi-select list with JavaScript...
noélie roux noélie roux
2020-03-20  11:41pm 2020-03-20 11:41pm
How skip unavailable video in Youtube if...
james warren james warren
2021-03-17  11:49am 2021-03-17 11:49am
webpage Flickering when scrolling to bot...
dylan soto dylan soto
2021-11-03  6:50pm 2021-11-03 6:50pm