fork download
  1. #......
  2. @app.route('/edit', methods=['GET', 'POST'])
  3. def edit():
  4. form = EditForm()
  5.  
  6. cur = mysql.connection.cursor()
  7. cur.execute('''SELECT * FROM User WHERE userId > 0''')
  8. un = cur.fetchall()
  9. cur = mysql.connection.cursor()
  10. cur.execute('''SELECT * FROM Course''')
  11. courses = cur.fetchall()
  12.  
  13. usernumber = 0
  14. usernumber = int(request.args.get('i'))
  15. uid = un[usernumber][0]
  16. print('uid: %d' % uid)
  17.  
  18. if request.method == 'POST':
  19. if form.validate() == False:
  20. flash('Name & Email fields are required.')
  21. return render_template('edit.html', form=form)
  22. else:
  23. cur = mysql.connection.cursor()
  24. cur.execute(
  25. "UPDATE User SET email='" +
  26. form.email.data +
  27. "', phone='" +
  28. form.phone.data +
  29. "', mphone='" +
  30. form.mphone.data +
  31. "', status='" +
  32. form.status.data +
  33. #"' WHERE userId='12' ") # ok
  34.  
  35. "' WHERE userId='" + uid + "' ")
  36. # TypeError: int() argument must be a string or a number,
  37. # not 'NoneType'
  38. # and IOError: [Errno 32] Broken pipe
  39.  
  40. rv = cur.fetchall()
  41. mysql.connection.commit()
  42. return 'ok'
  43.  
  44. elif request.method == 'GET':
  45. return render_template(
  46. 'edit.html',
  47. form=form,
  48. un=un,
  49. usernumber=usernumber,
  50. courses=courses)
  51.  
  52. if __name__ == '__main__':
  53. app.run(debug=True)
Runtime error #stdin #stdout #stderr 0.01s 8968KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
Traceback (most recent call last):
  File "prog.py", line 2, in <module>
NameError: name 'app' is not defined