Article From:
 11         <form method="POST" action="/home">
 12             <p>Please leave a message < /p>13 * < table>14 < tr>15 ≪ th> name < /th>16 < td> < input type= "text" size= "20" name= "name".> < /td>17 < /tr>18 < tr>Nineteen< th> message < /th>20 < td> < textarea rows= "5" cols= "40" name= "C"Omment "> < /textarea> < /td>21 < /tr>22 x < /taBle>23 * < p> < button type= "submit" onclick= "alert" (submitted successfully! ">"; submit < /button≫ < /p>24 < /form>

This is the code on my HTML.

2 @application.route('/home',methods=['GET','POST'])
 33 def index():
 34     '''The home page ''35 If request.method = ='GET':36 x greating_list = load_data ()37 x returnRender_template ('index.html', greating_list = greating_list)38 If request.method = ='POST':Three9 x name = request.form.get ('name')40 x comment = request.form.get ('comment')Forty-oneCreate_at = ()42 x sava_dATA (name, comment, create_at)

I don’t know why I can’t receive the POST request at all.

Answer 0:

I copied your code and run no problem.

Answer 1:

You have problems with your thinking.
I understand your thinking as follows:

  1. Display a main page with URL as /home.
  2. On this main page, you submit a form using the post request.
  3. The form is submitted on the home page, and the action of the form, which handles the post page, is also / home, and then returns to the / home page.

You are using HTML’s basic functions to implement Ajax behavior.This is certainly not possible.

So how do I receive the post request?

It is no problem to design a form form on the main page of /home. Next, you need to implement a view function that handles post requests, then action calls the URL of the view function you implement, and implements the new URLThe view template will finally jump to the new page after you send the post request.

OK, just so so !!!

Answer 2:

I don’t know if it can be submitted after your onclick, but you can open the browser F12 and see if there is any incoming data in the request to your interface

Similar Posts:

Leave a Reply

Your email address will not be published. Required fields are marked *