Função excluir

parent a5664ca4
......@@ -40,6 +40,13 @@ def editar(id):
return redirect(url_for('index'))
return render_template('editar.html', receita=receita)
@app.route('/excluir/<int:id>')
def excluir(id):
receita = Receita.query.get_or_404(id)
db.session.delete(receita)
db.session.commit()
return redirect(url_for('index'))
if __name__ == '__main__':
with app.app_context():
db.create_all()
......
......@@ -3,6 +3,7 @@
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="/static/style.css">
<title>Cadastro</title>
</head>
<body>
......
......@@ -3,6 +3,7 @@
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="/static/style.css">
<title>Editar Receita</title>
</head>
<body>
......@@ -12,6 +13,7 @@
<input id="nome" name="nome" type="text" value="{{ receita.nome }}" required>
<button type="reset">Limpar</button>
<button type="submit">Salvar</button>
<button type="button" onclick="location.href='/excluir/{{ receita.id }}'">Excluir</button>
</form>
</div>
</body>
......
......@@ -3,6 +3,7 @@
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="/static/style.css">
<title>Dishly</title>
</head>
<body>
......
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