javascriptpythonflaskhttp-error

Using js/flask, getting internal 500 error on using Post request


So I have a little project Im working on, that involves sending the text-area value, to the python side of my flask app, and my front end code looks like this

<input id="promptArea" type="text-area" placeholder="write your story..." />
<button id="submitButton">Make your story now!</button>
<p>your story here...</p>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
        <script>
        $(document).ready(function() {
            $('#submitButton').click(function (event) {
            event.preventDefault();
            $('#submitButton').prop("disabled", true);
            $.ajax({
                 data : { prompt : document.getElementById("promptArea").value },
                 type : 'POST',
                 url : '/prompt', //post grabbed text to flask endpoint for saving role
                 success: function (data) { console.log('Sent Successfully') },
                 error: function (e) { console.log('Submission failed...') }
            });
        });
        })
        </script>

I based this off here and I'm relatively new to flask and full stack apps, and I'm getting an error 500 on the JavaScript end, How do I fix this?

python side(if required)

@app.route('/prompt', methods=['POST', 'GET'])
def prompt():
    prompt = request.form['prompt'] #parse received content to variable
    chatbot.chat(prompt)
    return ("works", 205) #or whatever you wish to return

Solution

  • After checking server logs, I discovered I just had to add

    from flask import Flask, request