1

I want to send a html script to a python Flask route. It can be content of an html page (with tags and text content).

Here is the javascript portion:

var xhr = new XMLHttpRequest();
var url = "http://localhost:5000/todo/api/v1.0/process/" + htmlstring;  
xhr.open('GET', url, false);
xhr.send();
var retrievedtext = xhr.responseText; //This will be returned by Flask

The flask portion of the code is:

@app.route('/todo/api/v1.0/clean/<source_code>', methods=['GET'])
def process_html_code(source_code):
    //do processing
    return result

However, I always get 404 error when sending html as it is not allowed. What is a good approach to be able to send html to flask?

1 Answer 1

1

You need to use the same route in your Javascript code as you defined in your Python code.

In your flask app you defined a route

/todo/api/v1.0/clean/<source_code>

But in your Javascript code you try to send a request to

http://localhost:5000/todo/api/v1.0/process/

That doesn't fit. Change your url in the Javascript code according to the defined route:

var url = "http://localhost:5000/todo/api/v1.0/clean/" + htmlstring;  

This works.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.