Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial![](https://ecs-static.teamtreehouse.com/assets/views/marketing/shared/community-banner-white-47072046c51352fe6a69f5e691ff5700b28bb11d45197d7bdf066d9ea3f72d0c.webp)
![Trenton Spears](https://uploads.teamtreehouse.com/production/profile-photos/11548919/micro_Chappie_Wallpaper__1_.jpg)
Trenton Spears
Python Development Techdegree Graduate 16,969 PointsFlask with SQLAlchemy Basics > Connecting To A Database with SQLAlchemy > Working with A Plant Database
Bummer: Make sure your new_plant variable is inside of the form function's if statement.
Not sure what I'm getting wrong..
from models import db, Plant, app
from flask import render_template, url_for, request, redirect
@app.route('/')
def index():
return render_template('index.html')
@app.route('/form', methods=['GET', 'POST'])
def form():
if request.form:
new_plant = Plant(type=request.form['type'],
status=request.form['status'])
db.add(new_plant)
db.commit()
return redirect(url_for('index'))
return render_template('form.html')
if __name__ == '__main__':
app.run(host='0.0.0.0', port=8000)
from flask import Flask
from flask_sqlalchemy import SQLAlchemy
app = Flask(__name__)
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///plants.db'
db = SQLAlchemy(app)
class Plant(db.Model):
id = db.Column(db.Integer, primary_key=True)
plant_type = db.Column(db.String())
plant_status = db.Column(db.String())
{% extends 'layout.html' %}
{% block content %}
<form action="{{ url_form('form') }}" method="POST">
<label for="type">Plant Type:</label>
<input type="text" name="type" id="type" placeholder="Plant type">
<p>Plant Status:</p>
<label for="good">GOOD</label>
<input type="radio" name="status" id="good">
<label for="ok">OK</label>
<input type="radio" name="status" id="ok">
<label for="bad">BAD</label>
<input type="radio" name="status" id="bad">
</form>
{% endblock %}
{% extends 'layout.html' %}
{% block content %}
<h1>Our Plants:</h1>
<div>
<h2>Plant Type</h2>
<p>Plant Status</p>
</div>
{% endblock %}
1 Answer
![jb30](https://secure.gravatar.com/avatar/681668d7cc4c5486851384a0feddda37?s=96&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
jb30
44,806 Pointsclass Plant(db.Model):
id = db.Column(db.Integer, primary_key=True)
plant_type = db.Column(db.String())
plant_status = db.Column(db.String())
When you create a new plant, it should have plant_type
rather than type
and plant_status
rather than status
.
Trenton Spears
Python Development Techdegree Graduate 16,969 PointsTrenton Spears
Python Development Techdegree Graduate 16,969 PointsYou're awesome lol I just figured it out before your response, but thank you for your assistance!