You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
the code for me did not work for the handlers.py i hade to do this
this is because of the circular import of app
in handlers.py :
defget_handlers():
fromstarlette.exceptionsimportHTTPExceptionasStarletteHTTPExceptionfromapp.mainimportappfromapp.shortcutsimportrender, redirect, is_htmxfromapp.users.exceptionsimportLoginRequiredException# this is how am handling the http exception by changing it please dont forget how we are doing this since it is very very important @app.exception_handler(StarletteHTTPException)asyncdefhttp_exception_handler(request, exc):
status_code=exc.status_codetemplate_name='errors/main.html'ifstatus_code==404:
template_name='errors/404.html'context= {"status_code": status_code}
returnrender(request, template_name, context, status_code=status_code)
@app.exception_handler(LoginRequiredException)asyncdeflogin_required_exception_handler(request, exc):
response=redirect(f"/login?next={request.url}", remove_session=True)
ifis_htmx(request):
response.status_code=200response.headers['HX-Redirect'] =f"/login"returnresponse
and then inside main.py i changed the import to
from .handlersimportget_handlersget_handlers()
The text was updated successfully, but these errors were encountered:
the code for me did not work for the handlers.py i hade to do this
this is because of the circular import of app
in handlers.py :
and then inside main.py i changed the import to
The text was updated successfully, but these errors were encountered: