title: Displaying Table from Database using Python, Flask, Sqlalchemy, and HTML on pythonanywhere
body: <p>So I am trying to display a table from my db on my web app. however when I run the program, I get all of my data on 1 row instead of lined up in the proper columns. Parts of my HTML and Python code is below. I am using pythonanywhere to launch my web app.  Any advice on where I am messing up?</p>
  
  <p><strong>ID.HTML</strong></p>
  
  <pre><code>&lt;table style="margin-left: 20px;"&gt;
  &lt;!-- Table headers --&gt;
      &lt;th&gt;
           &lt;tr style="color: black; "&gt;
  
          &lt;th&gt;Last Name&lt;/th&gt;
          &lt;th&gt;First Name&lt;/th&gt;
          &lt;th&gt;SSN&lt;/th&gt;
          &lt;th&gt;MRN&lt;/th&gt;
          &lt;th&gt;Age&lt;/th&gt;
          &lt;th&gt;Sex&lt;/th&gt;
          &lt;th&gt;Incounter Type&lt;/th&gt;
          &lt;th&gt;Provider Last Name&lt;/th&gt;
          &lt;th&gt;Provider First Name&lt;/th&gt;
          &lt;th&gt;Admin Date&lt;/th&gt;
          &lt;th&gt;Admin Time&lt;/th&gt;
          &lt;th&gt;Hospital&lt;/th&gt;
          &lt;th&gt;Floor&lt;/th&gt;
          &lt;th&gt;Room&lt;/th&gt;
          &lt;th&gt;Bed&lt;/th&gt;
  
          &lt;/tr&gt;
      &lt;/th&gt;
  
      &lt;tr&gt;
      {%for patient_id in query%}
  
      &lt;td&gt;
          {{patient_id.lname}}
       &lt;/td&gt;
       &lt;td&gt;
          {{patient_id.fname}}
      &lt;/td&gt;
      &lt;td&gt;
          {{patient_id.ssn}}
      &lt;/td&gt;
      &lt;td&gt;
          {{patient_id.mrn}}
      &lt;/td&gt;
      &lt;td&gt;
          {{patient_id.age}}
      &lt;/td&gt;
      &lt;td&gt;
          {{patient_id.sex}}
      &lt;/td&gt;
      &lt;td&gt;
          {{patient_id.incounter_type}}
      &lt;/td&gt;
      &lt;td&gt;
          {{patient_id.provider_lname}}
      &lt;/td&gt;
      &lt;td&gt;
          {{patient_id.provider_fname}}
      &lt;/td&gt;
      &lt;td&gt;
          {{patient_id.admin_date}}
      &lt;/td&gt;
      &lt;td&gt;
          {{patient_id.admin_time}}
      &lt;/td&gt;
      &lt;td&gt;
          {{patient_id.location_hospital}}
      &lt;/td&gt;
      &lt;td&gt;
          {{patient_id.location_floor}}
      &lt;/td&gt;
      &lt;td&gt;
          {{patient_id.location_room}}
      &lt;/td&gt;
      &lt;td&gt;
          {{patient_id.location_bed}}
      &lt;/td&gt;
      {%endfor%}
      &lt;/tr&gt;
   &lt;/table&gt;
  </code></pre>
  
  <p><strong>flask_app.py</strong></p>
  
  <pre><code>class patient_ID(db.Model):
  
  __tablename__ = "patient_ID"
  
  incounter_types = [('inpatient', 'inpatient'),
                 ('outpatient', 'outpatient')
                 ]
  
  lname = db.Column(db.String(128))
  fname = db.Column(db.String(128))
  ssn = db.Column(db.String(9))
  mrn = db.Column(db.String(8),primary_key=True)
  age = db.Column(db.String(3))
  sex = db.Column(db.String(6))
  incounter_type = db.Column(db.String(128))#, choices=incounter_types)
  provider_lname = db.Column(db.String(128))
  provider_fname = db.Column(db.String(128))
  admin_date = db.Column(db.String(128))
  admin_time = db.Column(db.String(128))
  location_hospital = db.Column(db.String(128))
  location_floor = db.Column(db.String(3))
  location_room = db.Column(db.String(10))
  location_bed = db.Column(db.String(1))
  
  
  @app.route("/Patient_Info/", methods=["GET", "POST"])
  @login_required
  def patient_info_page():
       if request.method == "GET":
           return render_template("ID.html", query=patient_ID.query.all())
  
       if not current_user.is_authenticated:
           return redirect(url_for('index'))
       ID = patient_ID(mrn=request.form["mrns"])
  
       return redirect(url_for('patient_info_page'), query)
  </code></pre>