Create a WebApp which returns some result via Python

ML372951
ML372951 Registered Posts: 1
edited July 16 in Using Dataiku

Hi,

I trying to create a web app in which I can enter data via some form. The data should be processed via some Python snippet. But so far it is not working. Can somebody explain to me what I am doing wrong.

Attached my code and part of the error message.

HTML:

<link rel="stylesheet" href="/static/public/styles/1.0.0/dku-styles.css" />


<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Einfache Webanwendung</title>
</head>
<body>
    <h1>Einfache Webanwendung</h1>
    <form id="calcForm">
        <label for="number">Geben Sie eine Zahl ein:</label>
        <input type="number" id="number" name="number" required><br><br>
        <button type="submit" id="submit">Berechnen</button>
    </form>
    <div id="resultDiv"></div>
</body>

JS:

document.addEventListener('DOMContentLoaded', function () {
    const form = document.getElementById('calcForm');
    const resultDiv = document.getElementById('resultDiv');

    form.addEventListener('submit', function (e) {
        e.preventDefault();
        const number = parseFloat(document.getElementById('number').value);
        const test = await fetch(getWebAppBackendUrl('/calculate'), {
                method: 'POST',
                headers: {
                    'Content-Type': 'application/json',
                },
                body: JSON.stringify({number}),
        });
        document.getElementById("resultDiv").innerHTML = test;         

Python:

import dataiku
import pandas as pd


from flask import Flask, render_template, request, jsonify
import json  # Import the json module

@app.route('/calculate')
def calculate():
    test = request.args
    return json.dumps({"status" : "ok" , "num" : test})

Part of my error message is:

"message":"Required request parameter \u0027projectKey\u0027 for method parameter type String is not present"


Operating system used: Linux

Tagged:

Answers

Setup Info
    Tags
      Help me…