maces / fastapi-htmx

Extension for FastAPI to make HTMX easier to use.
GNU Lesser General Public License v3.0
238 stars 9 forks source link

Library seems broken? #18

Closed stonetwig closed 8 months ago

stonetwig commented 9 months ago

Whenever I try to use your library, as soon as I import fastapi_htmx I get this following error:

    import fastapi_htmx
  File "/home/user/.cache/pypoetry/virtualenvs/app-AJ5gfN-M-py3.10/lib/python3.10/site-packages/fastapi_htmx/__init__.py", line 3, in <module>
    from .htmx import HXRequest as HXRequest
  File "/home/user/.cache/pypoetry/virtualenvs/app-AJ5gfN-M-py3.10/lib/python3.10/site-packages/fastapi_htmx/htmx.py", line 134, in <module>
    htmx_init(templates=Jinja2Templates(directory=Path("my_app") / "templates"))#, on_error_redirect_to="/")
NameError: name 'Path' is not defined

I am a bit of a python noob so maybe I am doing something wrong but as soon as I remove the import statement the error goes away. Haven't found a way around it..

Rooyca commented 9 months ago

NameError: name 'Path' is not defined

Try from pathlib import Path

stonetwig commented 8 months ago

@Rooyca Thanks, but I already have imported that. The thing is, I call the function htmx_init with different parameters but the default "my_app" is still called for some reason?

omarisw commented 8 months ago

@stonetwig Did you try from pathlib import Path in the library site-packages/fastapi_htmx/htmx.py , this solve my issue.

maces commented 8 months ago

@stonetwig you are totally correct, the lib was broken with that release. My bad, sorry. Thanks very much for reporting it. It's fixed now, please reinstall/update the fastapi-htmx package to at least version 0.4.0 (for pip: pip install fastapi-htmx --upgrade). I created #23 to prevent this kind of error from happening again.

Thanks @Rooyca and @omarisw for helping out :)

stonetwig commented 8 months ago

@maces No worries, thank you for updating it so fast and for the hard work you do as an open source maintainer.

You have a nice package going here and its probably my favorite way of using htmx.