title: How do i go about on this error 'UnboundLocalError: local variable 'user' referenced before assignment'
body: <p>I am following Corey Schafer tutorials on flask and whenever I run python <code>run.py</code>, server starts, but when I click on my register button which is on my app. It's showing the  following error </p>
  
  <blockquote>
    <p>"UnboundLocalError: local variable 'user' referenced before assignment"</p>
  </blockquote>
  
  <p>I've tried editing the "user" field with no success</p>
  
  <p>My <code>routes.py</code> code:</p>
  
  <pre><code>from flask import render_template, url_for,flash,redirect
  from FLASKBLOG import app, db, bcrypt
  from FLASKBLOG.forms import RegistrationForm,LoginForm
  from FLASKBLOG.models import user
  
  posts = [
      {
          'author':'Denis muriuki',
          'title':'Blog post 1',
          'content':'Global Macro',
          'date_posted':'July 24,2019'
      }
  ]
  
  
  
  @app.route ("/")
  @app.route ("/home")
  def home():
      return render_template("home.html",posts=posts)
  
  @app.route("/about")
  def about():
      return render_template("about.html",title='about')
  
  @app.route("/register",methods=['GET','POST'])
  def register():
      form = RegistrationForm()
      if form.validate_on_submit():
          hashed_password = bcrypt.generate_password_hash(form.password.data).decode('utf-8')
          user = user(username=form.username.data, email=form.email.data, password=hashed_password)
          db.session.add(user)
          db.session.commit()
          flash('Your account has been created! You are now able to log in', 'success')
          return redirect(url_for('login'))
      return render_template("register.html",title='Register',form=form )
  
  @app.route("/login",methods=['GET','POST'])
  def login():
      form = LoginForm()
      if form.validate_on_submit():
          if form.email.data == 'admin@blog.com' and form.password.data == 'password':
              flash('You have been logged in!','success')
              return redirect(url_for('home'))
          else:
              flash('Login unsuccessful.please check username and password','danger')
      return render_template("login.html",title='Login',form=form )
  
  
  
  
  
  my models.py code
  from FLASKBLOG import db
  
  class user(db.Model):
      id = db.Column(db.Integer,primary_key=True)
      username = db.Column(db.String(20),unique=True,nullable=False)
      email = db.Column(db.String(120),unique=True,nullable=False)
      password = db.Column(db.String(60),nullable=False)
  
      def __repr__(self):
          return f"user('{self.username}',{self.email}')"
  
  
  my __init__.py code
  rom flask import Flask
  from flask_sqlalchemy import SQLAlchemy
  from flask_bcrypt import Bcrypt
  
  
  app = Flask(__name__)
  app.config['SECRET_KEY']='e95b70cb73d3e650884d944ce06fff25'
  app.config['SQLAlCHEMY_DATABASE_URI'] ='sqlite:////home/denis/Desktop/flaskblog/site.db'
  db = SQLAlchemy(app)
  bcrypt = Bcrypt(app)
  
  
  from FLASKBLOG import route
  </code></pre>