DEV Community

Raja Simon
Raja Simon

Posted on

2

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

Heroku

Build apps, not infrastructure.

Dealing with servers, hardware, and infrastructure can take up your valuable time. Discover the benefits of Heroku, the PaaS of choice for developers since 2007.

Visit Site

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more