HTMX not loading

Thanks.

I did actually notice that the HTMX JavaScript appeared to be correct in the console when I expanded it.

I’ll try the hard reload to see if that does anything.

As a side note, this:

is never going to be “True”, because this data element is being rendered when the page is requested, not when htmx is issuing the request.

How are you running runserver? Please be completely specific and detailed about exactly what you’re doing.

Also check your network tab to see if you’re issuing a GET for that url.

I’m not sure if this helps, but I use PyCharm for my Django IDE, so I’m using the PyCharm RUN console. Here is a screen capture.

I understand what you’re saying about the {{ htmx_status }} entry. I have taken that out.

I don’t see any GET happening at all from the Network tab. I’m assuming you mean I should see a GET to the /albums/album_partial_gallery/ view? Not 100% sure if that’s the URL you are referring to.

There should be more that shows up there - you should see a line for each request that gets made to your server.

If you don’t, then you need to find what settings to make to show that information to you.

If it doesn’t have one, then you should run runserver directly from the command line and stop using that console.

If what you’re showing is all that it can show you, then it’s a tool you should avoid, because there’s a lot of useful information to be had.

(More likely, I’m guessing there’s some setting that may need to be changed, because my understanding is that PyCharm is far too good of a product for this to be an actual limitation within it.)

Correct.

Also, please post your url definition for /albums/album_partial_gallery/

Here is the url.

path('album-partial-gallery/', views.album_partial_gallery, name='album_partial_gallery'),

Can I assume that the GET for /albums/album_partial_gallery/ would happen when the HTMX “get” is executed? Otherwise, there’s nothing to request that view. My assumption is that if the “hx_get” is processed, then I would have been redirected to the view, but that never happens. That was the whole reason for this post.

Also, noted that I should possibly avoid PyCharm, but I’ve had great luck with it so far. If that is causing limitations in my ability to debug, then I will look for other solutions.

Thanks again!

Note - it’s hx-get, not hx_get. See the docs at </> htmx ~ Documentation

You’re not being “redirected”. If the hx-get is triggered, it executes a get on that url, and replaces the target div with the response.

There are many things that need to happen for this all to work.

  • A page must be loaded
  • HTMX must be loaded
  • HTMX must be triggered by an event
  • HTMX must send an AJAX request based upon the event
  • The server must receive the AJAX request
  • Django needs to call a view to handle that request
  • Django needs to send an html element (usually a <div>) as a response from that view
  • HTMX must inject that div into the DOM

What I’m trying to determine is where the process is broke.

Okay, first I re-read your original message and I see that you are not faulting PyCharm, you are potentially faulting my coding abilities…wise man :grinning_face_with_smiling_eyes:

I was almost certain that I copied the code snippet from another example, so I didn’t even notice that I had “hx_get” instead of “hg-get”. That made the difference. I was then able to see a 404 error with the GET attempt.

That lead me to realize that the URL needed to be set as follows:

<div hx-get="{% url 'album_partial_gallery' %}" hx-trigger="load">

Once I made that change it is working! Phew!!

Again, I appreciate all of your help and patience. I’ll keep my carpentry tools handy for now, but maybe not today!!