DEV Community

Raja Simon
Raja Simon

Posted on

How to redirect from server side in HTMX

Advantage of using HTMX is it feels like snappy. Since I am a backend developer in Python I have used HTMX in Django and Flask. But you can also use this in any server side frameworks including Ruby on Rails and ExpressJS. Or anything that server HTML from the server can use HTMX.

When I was developing the application I come across this problem. I need to redirect the user from server side to different page. But HTMX is making Ajax request on the front and getting response from the backend to change the HTML on the run. So to make this happen HTMX support headers. It will scan for HX-Redirect header present in the response headers if it is then it will make the redirect.

In this blog I’m going to explain this concept in details you can use this in your backend framework.

Click this link to view full article. Originally published on Raja Simon's blog

Top comments (0)