#código
from flask import Flask, render_template, request
class Jogo:
def __init__(self, nome, categoria, console):
self.nome = nome
self.categoria = categoria
self.console = console
jogo1 = Jogo('Tetris', 'Puzzle', 'Atari')
jogo2 = Jogo('God of War', 'Hack n Slash', 'PS2')
jogo3 = Jogo('Mortal Kombat', 'Luta', 'PS2')
lista = [jogo1, jogo2, jogo3]
app = Flask(__name__)
@app.route('/inicio')
def ola():
return render_template('lista.html', titulo='Jogos', jogos=lista)
@app.route('/novo')
def novo():
return render_template('novo.html', titulo='Novo Jogo')
@app.route('/criar', methods=['POST',1])
def criar():
nome=request.form['nome']
categoria=request.form['categoria']
console=request.form['console']
jogo=Jogo(nome, categoria, console)
lista.append(jogo)
return render_template('lista.html',titulo='Jogo', jogos=lista)
app.run(debug=True)
mensagem de erro
C:\Users\user\PycharmProjects\pythonProject1\venv\Scripts\python.exe C:\Users\user\PycharmProjects\pythonProject1\jogoteca.py
Traceback (most recent call last):
File "C:\Users\user\PycharmProjects\pythonProject1\jogoteca.py", line 20, in <module>
def novo():
File "C:\Users\user\PycharmProjects\pythonProject1\venv\lib\site-packages\flask\scaffold.py", line 449, in decorator
self.add_url_rule(rule, endpoint, f, **options)
File "C:\Users\user\PycharmProjects\pythonProject1\venv\lib\site-packages\flask\scaffold.py", line 50, in wrapper_func
return f(self, *args, **kwargs)
File "C:\Users\user\PycharmProjects\pythonProject1\venv\lib\site-packages\flask\app.py", line 1354, in add_url_rule
rule = self.url_rule_class(rule, methods=methods, **options)
File "C:\Users\user\PycharmProjects\pythonProject1\venv\lib\site-packages\werkzeug\routing\rules.py", line 455, in __init__
raise ValueError("urls must start with a leading slash")
ValueError: urls must start with a leading slash
Process finished with exit code 1