Forums

HTMX does not work on Pythonanywhere

Hello there, I am using HTMX to execute POST and GET request, everything works fine on my local on connecting to a flask server but once I deploy it on PythonAnywhere, the links do not work , has anyone faced this issue before?

Could you provide an example of your rendered HTMX?

It works. I have it in my app. You can get some tips here https://www.youtube.com/watch?v=3dyQigrEj8A But though I am using Django framework and not flask.

I think one way to tackle this problem could be to make sure that you're really linking to the HTMX .js file properly.

I'd say do a test to make sure you're really loading the file. Perhaps use their CDN in the header of your site.

This is what I am using, in my flask app here on pythonanywhere:

<script src="https://unpkg.com/htmx.org@1.5.0"></script>

In your settings.py

set as below:

STATIC_ROOT = os.path.join(BASE_DIR, "static")

STATIC_URL = "/static/"

STATICFILES_DIRS = [
    os.path.join(BASE_DIR, "/static/")
]

MEDIA_ROOT = os.path.join(BASE_DIR, "/home/myusername/myproject/myapp/media/")

MEDIA_URL = "/media/"

Then run pythonxX.Y manage.py collectstatic. pythonX.Y(e.g python3.10)

Your HTMX should work.

@acrossglobe, @totelian -- thanks for the tips! (I've only added some formatting to your posts)