Hola, tengo la siguiente situación: estoy haciendo un registro de usuario con python en flask y me esta presentado el siguiente error:
Gracias
Error:
Traceback (most recent call last):
File "/home/yoel/curso-python/todoer/venv/bin/flask", line 8, in <module>
sys.exit(main())
File "/home/yoel/curso-python/todoer/venv/lib/python3.8/site-packages/flask/cli.py", line 1054, in main
cli.main()
File "/home/yoel/curso-python/todoer/venv/lib/python3.8/site-packages/click/core.py", line 1055, in main
rv = self.invoke(ctx)
File "/home/yoel/curso-python/todoer/venv/lib/python3.8/site-packages/click/core.py", line 1657, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "/home/yoel/curso-python/todoer/venv/lib/python3.8/site-packages/click/core.py", line 1404, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/home/yoel/curso-python/todoer/venv/lib/python3.8/site-packages/click/core.py", line 760, in invoke
return __callback(*args, **kwargs)
File "/home/yoel/curso-python/todoer/venv/lib/python3.8/site-packages/click/decorators.py", line 84, in new_func
return ctx.invoke(f, obj, *args, **kwargs)
File "/home/yoel/curso-python/todoer/venv/lib/python3.8/site-packages/click/core.py", line 760, in invoke
return __callback(*args, **kwargs)
File "/home/yoel/curso-python/todoer/venv/lib/python3.8/site-packages/flask/cli.py", line 918, in run_command
raise e from None
File "/home/yoel/curso-python/todoer/venv/lib/python3.8/site-packages/flask/cli.py", line 904, in run_command
app = info.load_app()
File "/home/yoel/curso-python/todoer/venv/lib/python3.8/site-packages/flask/cli.py", line 308, in load_app
app = locate_app(import_name, name)
File "/home/yoel/curso-python/todoer/venv/lib/python3.8/site-packages/flask/cli.py", line 235, in locate_app
return find_best_app(module)
File "/home/yoel/curso-python/todoer/venv/lib/python3.8/site-packages/flask/cli.py", line 63, in find_best_app
app = app_factory()
File "/home/yoel/curso-python/todoer/todo/__init__.py", line 22, in create_app
app.register_blueprint(auth.bp)
File "/home/yoel/curso-python/todoer/venv/lib/python3.8/site-packages/flask/scaffold.py", line 50, in wrapper_func
return f(self, *args, **kwargs)
File "/home/yoel/curso-python/todoer/venv/lib/python3.8/site-packages/flask/app.py", line 1296, in register_blueprint
blueprint.register(self, options)
File "/home/yoel/curso-python/todoer/venv/lib/python3.8/site-packages/flask/blueprints.py", line 439, in register
deferred(state)
File "/home/yoel/curso-python/todoer/venv/lib/python3.8/site-packages/flask/blueprints.py", line 491, in <lambda>
lambda s: s.add_url_rule(
File "/home/yoel/curso-python/todoer/venv/lib/python3.8/site-packages/flask/blueprints.py", line 112, in add_url_rule
self.app.add_url_rule(
File "/home/yoel/curso-python/todoer/venv/lib/python3.8/site-packages/flask/scaffold.py", line 50, in wrapper_func
return f(self, *args, **kwargs)
File "/home/yoel/curso-python/todoer/venv/lib/python3.8/site-packages/flask/app.py", line 1358, in add_url_rule
raise AssertionError(
AssertionError: View function mapping is overwriting an existing endpoint function: auth.register
Función
bp = Blueprint('auth',__name__, url_prefix='/auth')
#Función para el registro del usuario
@bp.route('/register', methods=['GET','POST'])
def register():
if request.method == 'POST':
username = request.form['username']
password = request.form['password']
db, c = get_db()
error = None
c.execute(
'select id from usuer where username = %s'
)
if not username:
error = 'EL usuario es requerido'
if not password:
error = 'EL password es requerido'
elif c.fetchone() is not None:
error = 'El usuarioa () se encuentra registrado,'.format(username)
if error is None:
c.execute(
'insert intro user (username,password)value(%s,%s)',
(username, generate_password_hash(password))
)
c.commit()
return redirect(url_for('auth.login'))
flash(error)
return render_template('auth/register.html')