Guest User

Untitled

a guest
Sep 21st, 2018
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.40 KB | None | 0 0
  1. @app.route("/register", methods=["GET", "POST"])
  2. def register():
  3. """Register user"""
  4.  
  5. # User reached route via POST (as by submitting a form via POST)
  6. if request.method == "POST":
  7.  
  8. # Stored POST data to variables
  9. username = request.form.get('username')
  10. password = request.form.get('password')
  11. confirmation = request.form.get('confirmation')
  12.  
  13. # Ensure username was submitted
  14. if not username:
  15. return apology("must provide username", 403)
  16.  
  17. # Ensure password and confirmation were both submitted
  18. elif not password:
  19. return apology("must provide password in both fields", 403)
  20.  
  21. # Ensure passwords match
  22. elif confirmation != password:
  23. return apology("passwords do not match", 403)
  24.  
  25. elif db.execute('SELECT id FROM users WHERE username = ?',
  26. (username,)).fetchone() is not None:
  27. return apology("Username already exists", 403)
  28.  
  29. elif db.execute('SELECT id FROM users WHERE username = ?',
  30. (username,)).fetchone() is not None:
  31. TypeError: execute() takes 2 positional arguments but 3 were given
  32.  
  33. from cs50 import SQL; and
  34. db = SQL("sqlite:///finance.db")
  35.  
  36. import sqlite3; and
  37. db = sqlite3.connect('finance.db')
  38.  
  39. elif db.execute('SELECT id FROM users WHERE username = ?',
  40. (username,)).fetchone() is not None:
  41. return apology("Username already exists", 403)
Add Comment
Please, Sign In to add comment