Função excluir

parent a5664ca4
...@@ -40,6 +40,13 @@ def editar(id): ...@@ -40,6 +40,13 @@ def editar(id):
return redirect(url_for('index')) return redirect(url_for('index'))
return render_template('editar.html', receita=receita) 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__': if __name__ == '__main__':
with app.app_context(): with app.app_context():
db.create_all() db.create_all()
......
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,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="/static/style.css">
<title>Cadastro</title> <title>Cadastro</title>
</head> </head>
<body> <body>
......
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,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="/static/style.css">
<title>Editar Receita</title> <title>Editar Receita</title>
</head> </head>
<body> <body>
...@@ -12,6 +13,7 @@ ...@@ -12,6 +13,7 @@
<input id="nome" name="nome" type="text" value="{{ receita.nome }}" required> <input id="nome" name="nome" type="text" value="{{ receita.nome }}" required>
<button type="reset">Limpar</button> <button type="reset">Limpar</button>
<button type="submit">Salvar</button> <button type="submit">Salvar</button>
<button type="button" onclick="location.href='/excluir/{{ receita.id }}'">Excluir</button>
</form> </form>
</div> </div>
</body> </body>
......
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,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="/static/style.css">
<title>Dishly</title> <title>Dishly</title>
</head> </head>
<body> <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