Primeiro Commit

parent d065ee68
from flask import Flask, render_template, request, redirect
from models import db, Animal
app = Flask(__name__)
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///fazenda.db'
db.init_app(app)
with app.app_context():
db.create_all() # Cria o arquivo do banco automaticamente
@app.route('/')
def index():
lista = Animal.query.all()
return render_template('index.html', animais=lista)
\ No newline at end of file
from flask_sqlalchemy import SQLAlchemy
db = SQLAlchemy()
class Animal(db.Model):
id = db.Column(db.Integer, primary_key=True)
nome = db.Column(db.String(50), nullable=False)
especie = db.Column(db.String(50), nullable=False)
idade = db.Column(db.Integer)
peso = db.Column(db.Float)
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment