def register_user(): form = RegistrationForm() if current_user.is_authenticated: flash('you are already registered') return redirect(url_for('main.display_books')) if form.validate_on_submit(): User.create_user( user=form.name.data, email=form.email.data, password=form.password.data) flash('Registration Successful') return redirect(url_for('authentication.do_the_login')) return render_template('registration.html', form=form)
from app import create_app from app import db from app.authentication.models import User from sqlalchemy import exc flask_app = create_app('prod') with flask_app.app_context(): db.create_all() try: if not User.query.filter_by(user_name = 'sherlock holmes').first(): User.create_user(user = '******', email='*****@*****.**', password = '******') except: exc.IntegretiyError flask_app.run()