title: How can I login a user in my flask web app when they have signed up?
body: <p>I am developing a book review web app in flask using PostgreSQL database. However, I am stuck on how to login a user and track their session and once a user logs-in he must be taken to a html page where he can search for a book and add a review. I know we can use <code>sessions</code> in flask. But, I am really confused on how do I do it.</p>
  
  <p><code>application.py</code></p>
  
  <pre><code>@app.route("/signin",methods=["GET","POST"])
  def signin():
      if request.method=="GET":
          session["user_id"] = user_id     #ERROR ON THIS LINE
          return render_template("login.html")
      else:
          return render_template("search.html")
  </code></pre>
  
  <p>My <code>users</code> table in the database which stores the username,password and user_id</p>
  
  <pre><code> Table "public.users"
    Column  |         Type          | Collation | Nullable |                Default                 
  ----------+-----------------------+-----------+----------+----------------------------------------
   username | character varying(30) |           | not null | ''::character varying
   password | character varying(30) |           | not null | ''::character varying
   user_id  | integer               |           | not null | nextval('users_user_id_seq'::regclass)
  Indexes:
      "users_pkey" PRIMARY KEY, btree (user_id)
  </code></pre>