diff --git a/app.py b/app.py index 69ca0bb..b4bfd14 100644 --- a/app.py +++ b/app.py @@ -1,4 +1,4 @@ -from flask import Flask, render_template, request, redirect, url_for, flash, session +from flask import Flask, render_template, request, redirect, url_for, flash, session, jsonify from flask_sqlalchemy import SQLAlchemy from flask_migrate import Migrate from datetime import datetime @@ -6,6 +6,7 @@ from werkzeug.security import generate_password_hash, check_password_hash from werkzeug.utils import secure_filename import os from config import Config +import random app = Flask(__name__) app.config.from_object(Config) @@ -1438,6 +1439,20 @@ def seed_db(): )) db.session.commit() +@app.route('/recognize-plant', methods=['GET', 'POST']) +def recognize_plant(): + if request.method == 'GET': + return render_template('recognize_plant.html') + + # For proof of concept, just return a random plant + plants = Plant.query.all() + if not plants: + flash('No plants found in the database.', 'warning') + return redirect(url_for('home')) + + random_plant = random.choice(plants) + return jsonify({'redirect': url_for('plant', plant_id=random_plant.id)}) + if __name__ == "__main__": with app.app_context(): db.create_all() # Create all tables diff --git a/templates/base.html b/templates/base.html index 438d9e4..23ff8e2 100644 --- a/templates/base.html +++ b/templates/base.html @@ -10,25 +10,21 @@
-