0

Could you please help me with Python-Flask server misunderstanding. I have some project with flask, it perfectly works on local server 127.0.0.1, but when I moved it to the Web Server (blue host), some of my script give me these errors:

Here I have jQuery, Ajax response to show a table without reloading page:

<button class="myButton" id = "Lbutton">Load</button>

<script>

$("#Lbutton").click(function(){

  $.ajax({
          url: "/table,
          type: "get",
          data: {jsdata: $( "#select option:selected" ).text()},
          success: function(response) {
            $("#place_for_suggestions").html(response);

          },
          error: function(xhr) {
            // handle error
          }
        });

});

</script>

url: "/table, is the link for Flask function:

@FlaskApp2.route('/table')
def table():

    modid = request.args.get('jsdata')
    return render_template('table.html')

But finally the Server gave me error:

File does not exist: /home1/user/public_html/table

Why direct link for action, server understand like a link for a file?

So, every action to Python-Flask

<form action="/sendemail" method="post">

the Server understand like a link and give an error message !

What I'm doing wrong ?

2 Answers 2

3

Solved, I need to put the full path in action and route() decorator @app.route "/.../templates/table.html"

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

Comments

0

Most likely you need to add the POST method to your route definition.

@FlaskApp2.route('/table')

becomes:

@FlaskApp2.route('/table', methods=['GET', 'POST'])

Check out the documentation here: http://flask.pocoo.org/docs/0.12/quickstart/#http-methods

Which has an example of an endpoint that accepts both GET and POST HTTP methods.

Also check out a related question: Flask example with POST

2 Comments

Tried, doesn't help! Why its work on local server 127.0.0.1?
Maybe I need to write a full path in url: "templates/table",

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.