@vote.route('/signup', methods=['GET', 'POST']) defsignup(): if request.method == 'POST': # get user details from the form email = request.form['email'] username = request.form['username'] password = request.form['password']
# hash the Password password = generate_password_hash(password)
user = models.Users(email=email, username=username, password=password) db.session.add(user) db.session.commit()
flash('Thanks for signing up. Please login.')
return redirect(url_for('home'))
return render_template('signup.html')
修改siginup.html如下:
<!DOCTYPE html> <htmllang="en">
<head> <metacharset="utf-8"> <metahttp-equiv="X-UA-Compatible"content="IE=edge"> <metaname="viewport"content="width=device-width, initial-scale=1"> <!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags --> <metaname="description"content=""> <metaname="author"content=""> <linkrel="icon"href="https://getbootstrap.com/docs/3.3/favicon.ico">
<!-- IE10 viewport hack for Surface/desktop Windows 8 bug --> <linkhref="{{ url_for('static', filename='css/ie10-viewport-bug-workaround.css') }}"rel="stylesheet">
<!-- Custom styles for this template --> <linkhref="{{ url_for('static', filename='css/signin.css') }}"rel="stylesheet">
<!-- Just for debugging purposes. Don't actually copy these 2 lines! --> <!--[if lt IE 9]><script src="../../assets/js/ie8-responsive-file-warning.js"></script><![endif]--> <scriptsrc="{{ url_for('static', filename='js/ie-emulation-modes-warning.js') }}"></script>
<!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries --> <!--[if lt IE 9]> <script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script> <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script> <![endif]--> </head>