ch5 Section 4 : Be my magician

Dear, would you like to be my magician, to get out of the "correct" and “search” button back for me?


Here is the final step:

Step one

  1. Now you have the function(baby, see how happy you are!! You kep smiling all day)to store the data, it's time to try to "correct" the data.

  2. But unfortunately, you need ONE MORE FUNCTION!!

  3. Don't be upset, the hero was sitting just next to you!!

So here is the solution:

(1)Use "Query" to search the record and then change the data "weather" one, which is the second element in the list(weather = l[1]).

(2)Use the way:

    db.session.add()
    db.session.commit()

to update the data of the database.

Step two

  1. Add the “correct” button in the index.html page;

  2. The parameter of “correct” bottun is the same value as the input text "cityname". MUST know how to write the code.

  3. Use "request - POST" to fetch the date, not "GET".And by the way, I got my “search” button back!


elif request.form['button'] == 'correct':
        ustr = request.form['cityname']
        print(ustr)
        l = ustr.split( )
        updatweatherapi(l) #Here is the point!! send 'l' to 'updatweatherapi' function
        return render_template('index5.html')
  1. YES, IT'S DONE.
  2. AM I DREAMING? Pinch my arm, please!!

results matching ""

    No results matching ""