-1

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 ?

TheRutubeify
  • 532
  • 1
  • 6
  • 18

2 Answers2

2

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

TheRutubeify
  • 532
  • 1
  • 6
  • 18
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

Jim Factor
  • 1,151
  • 1
  • 11
  • 21