App.py funcionando

parent bebb32bd
...@@ -2,10 +2,15 @@ from flask import Flask, render_template, request, redirect, url_for ...@@ -2,10 +2,15 @@ from flask import Flask, render_template, request, redirect, url_for
from flask_sqlalchemy import SQLAlchemy from flask_sqlalchemy import SQLAlchemy
import os import os
app = Flask(__name__) ROOT_DIR = os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))
app = Flask(
__name__,
template_folder=os.path.join(ROOT_DIR, 'templates'),
static_folder=os.path.join(ROOT_DIR, 'static')
)
# Caminho do banco # Caminho do banco
basedir = os.path.abspath(os.path.dirname(__file__)) basedir = ROOT_DIR
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///' + os.path.join(basedir, 'animais.db') app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///' + os.path.join(basedir, 'animais.db')
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
...@@ -56,8 +61,8 @@ def index(): ...@@ -56,8 +61,8 @@ def index():
animais = Animal.query.all() animais = Animal.query.all()
return render_template('index.html', animais=animais) return render_template('index.html', animais=animais)
@app.route('/cadastro', methods=['GET', 'POST']) @app.route('/cadastrar', methods=['GET', 'POST'])
def cadastro(): def cadastrar():
if request.method == 'POST': if request.method == 'POST':
try: try:
novo = Animal( novo = Animal(
...@@ -78,7 +83,7 @@ def cadastro(): ...@@ -78,7 +83,7 @@ def cadastro():
db.session.rollback() db.session.rollback()
return f"Erro ao cadastrar: {str(e)}" return f"Erro ao cadastrar: {str(e)}"
return render_template('cadastro.html') return render_template('cadastrar.html')
@app.route('/delete/<int:id>') @app.route('/delete/<int:id>')
def delete(id): def delete(id):
......
# Relatório de Animais # Relatório de Animais
Nenhum animal cadastrado. ## Marcos
- Espécie: Pitcher
- Idade: 17 anos
- Peso: 67.0 kg
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
<head> <head>
<meta charset="UTF-8"> <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="{{ url_for('static', filename='static/style.css') }}"> <link rel="stylesheet" href="{{ url_for('static', filename='style.css') }}">
<link rel="preconnect" href="https://fonts.googleapis.com"> <link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin> <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Lexend:wght@100..900&display=swap" rel="stylesheet"> <link href="https://fonts.googleapis.com/css2?family=Lexend:wght@100..900&display=swap" rel="stylesheet">
...@@ -17,7 +17,7 @@ ...@@ -17,7 +17,7 @@
Nome: <input type="text" name="nome" required><br> Nome: <input type="text" name="nome" required><br>
Especie: <input type="text" name="especie" required><br> Especie: <input type="text" name="especie" required><br>
Idade: <input type="number" name="idade" required><br> Idade: <input type="number" name="idade" required><br>
Peso: <input type="number" name="cidade" required><br> Peso: <input type="number" step="any" name="peso" required><br>
<button type="submit">Salvar</button> <button type="submit">Salvar</button>
</form> </form>
</body> </body>
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
<head> <head>
<meta charset="UTF-8"> <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="{{ url_for('static', filename='static/style.css') }}"> <link rel="stylesheet" href="{{ url_for('static', filename='style.css') }}">
<link rel="preconnect" href="https://fonts.googleapis.com"> <link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin> <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Lexend:wght@100..900&display=swap" rel="stylesheet"> <link href="https://fonts.googleapis.com/css2?family=Lexend:wght@100..900&display=swap" rel="stylesheet">
......
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