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 = datetime.now ()42 x sava_dATA (name, comment, create_at)
I don’t know why I can’t receive the POST request at all.
I copied your code and run no problem.
You have problems with your thinking.
I understand your thinking as follows:
- Display a main page with URL as /home.
- On this main page, you submit a form using the post request.
- 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 !!!
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
- Django— simple from form submission
- Contenteditable= “true” can not be submitted to PHP. What should we do?
- BootstrapValidator is not able to submit forms, is it correct?
- How do I debug the validate_on_submit in flask_wtf?
- Additions, deletions and changes of MVC and Razor
- How many fields did laravel5.4 submit to the form?
- How do I debug when I submit a form form?
- Inheritance of TP template
- How does Django render data from a page post to another page?