Closed TheGeolama closed 2 years ago
Thanks for bringing this up! This looks like it is the result of a change between v21.3 and v21.6 (when the chapter was written). Basically what is happening is the autodiscover
is trying to load both the Blueprint
and the BlueprintGroup
.
I will get a correction for this up probably later today.
Still working on a fix for this?
I just pushed a fix. In short, before we add the BlueprintGroup
, we make sure to filter out any blueprints attached to it.
Please keep me informed of any more challenges you see. :heart:
sanic is installed in a virutalenv. Within the Chapter02/booktracker folder, I issue this command at the Windows Command prompt:
sanic src.server:app -p 7777 --debug --workers=2
I get this traceback:
Traceback (most recent call last): File "C:\Program Files\Python310\lib\runpy.py", line 196, in _run_module_as_main return _run_code(code, main_globals, None, File "C:\Program Files\Python310\lib\runpy.py", line 86, in _run_code exec(code, run_globals) File "D:\Development\PyCharmProjects\Python-Web-Development-with-Sanic-main\venv\Scripts\sanic.exe__main.py", line 7, in
File "D:\Development\PyCharmProjects\Python-Web-Development-with-Sanic-main\venv\lib\site-packages\sanic\ main.py", line 12, in main
cli.run()
File "D:\Development\PyCharmProjects\Python-Web-Development-with-Sanic-main\venv\lib\site-packages\sanic\cli\app.py", line 82, in run
app = self._get_app()
File "D:\Development\PyCharmProjects\Python-Web-Development-with-Sanic-main\venv\lib\site-packages\sanic\cli\app.py", line 135, in _get_app
module = import_module(module_name)
File "C:\Program Files\Python310\lib\importlib\init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "", line 1050, in _gcd_import
File "", line 1027, in _find_and_load
File "", line 1006, in _find_and_load_unlocked
File "", line 688, in _load_unlocked
File "", line 883, in exec_module
File "", line 241, in _call_with_frames_removed
File "D:\Development\PyCharmProjects\Python-Web-Development-with-Sanic-main\Chapter02\booktracker\src\server.py", line 4, in
app = create_app()
File "D:\Development\PyCharmProjects\Python-Web-Development-with-Sanic-main\Chapter02\booktracker\src\utilities\app_factory.py", line 22, in create_app
autodiscover(app, *init_blueprints)
File "D:\Development\PyCharmProjects\Python-Web-Development-with-Sanic-main\Chapter02\booktracker\src\utilities\autodiscovery.py", line 28, in autodiscover
app.blueprint(bp)
File "D:\Development\PyCharmProjects\Python-Web-Development-with-Sanic-main\venv\lib\site-packages\sanic\app.py", line 527, in blueprint
blueprint.register(self, options)
File "D:\Development\PyCharmProjects\Python-Web-Development-with-Sanic-main\venv\lib\site-packages\sanic\blueprints.py", line 357, in register
route = app._apply_route(apply_route)
File "D:\Development\PyCharmProjects\Python-Web-Development-with-Sanic-main\venv\lib\site-packages\sanic\app.py", line 393, in _apply_route
routes = self.router.add(params)
File "D:\Development\PyCharmProjects\Python-Web-Development-with-Sanic-main\venv\lib\site-packages\sanic\router.py", line 137, in add
route = super().add(params) # type: ignore
File "D:\Development\PyCharmProjects\Python-Web-Development-with-Sanic-main\venv\lib\site-packages\sanic_routing\router.py", line 243, in add
group.merge(existing_group, overwrite, append)
File "D:\Development\PyCharmProjects\Python-Web-Development-with-Sanic-main\venv\lib\site-packages\sanic_routing\group.py", line 160, in merge
raise RouteExists(
sanic_routing.exceptions.RouteExists: Route already registered: book [GET]