CodeNewbie Community 🌱

Discussion on: Django + HTMX CRUD application

Collapse
 
jacobvarney profile image
jacobvarney

This is great, thank you Rajesh! I was thinking about how to incorporate interactions with a database using Django without navigating to other pages. I really appreciate seeing how HTMX can be used to make that process easier and I will definitely be trying that soon.

Your example has the full page being rendered when replacing content, which makes me wonder how you would decide if you should use HTMX to render content or if you should just load in a new page. I think for creation, I would redirect the user to a new page. Or, maybe your list view adds a close button that you can use to remove elements and re-render the list.

Collapse
 
jacobvarney profile image
jacobvarney • Edited

I also tried downloading and completing an initial migration using the code provided and I couldn't figure out how to fix an error that came up. I deleted the dependency mentioned with no success. Should I have expected this to happen?

django.db.migrations.exceptions.NodeNotFoundError: Migration user.0001_initial dependencies reference nonexistent parent node ('auth', '0012_alter_user_first_name_max_length')

Collapse
 
mr_destructive profile image
Meet Rajesh Gor

Maybe clear the migration folder and try again:
It worked for me on a fresh repo
Image description

Thread Thread
 
jacobvarney profile image
jacobvarney

Thanks! My problem was actually resolved by changing the version of Django I was using. I was using Django 3 instead of 4.0.6 as noted in the settings. I made a rookie mistake (for the second time 😅).

It works exactly as demonstrated!

Collapse
 
jeery34 profile image
jeery34

Creating a CRUD (Create, Read, Update, Delete) application with Django and HTMX can be challenging for developers who are new to these technologies. While Django and HTMX both provide powerful tools for building web applications, integrating the two frameworks can be difficult. Additionally, developers must be familiar with HTML, CSS, and JavaScript in More order to effectively use HTMX. Furthermore, there are many different ways to structure a Django-HTMX application and developers must consider how to best structure the application to meet their specific needs. Finally, the debugging process for a Django-HTMX application can be time-consuming and difficult due to the complexity of the two frameworks.

Collapse
 
mr_destructive profile image
Meet Rajesh Gor • Edited

Hey thanks for reading and the feedback, it makes sense to render the new page as I want to replace the form with the list in the first place, it's not a good UI but I just experimented with the things I knew. So, we can render the entire page but by sending a hx-request, we want to specify where we want it to be replaced instead of re-loading the page entirely.

Please forgive me in the UI part :(
It's just not my thing. And BTW my name is Meet :)

Collapse
 
jacobvarney profile image
jacobvarney

Hi Meet! Thank you for your reply, and I'm sorry if my comment came of as a critique.

What you did worked great as an example. I was curious about something tangential: what do you consider when deciding whether to open a new page for updated content instead of rendering it in an element marked with an HTMX attribute? I think cards that you can delete and then reorganize on a grid would be a good example of when to use HTMX.

Thread Thread
 
mr_destructive profile image
Meet Rajesh Gor

No not all it's not critique at all, I feel good when someone comments on my articles, It gives a "someone's reading my articles" vibe.
Yes, we can use cards kind of thing, we can embed those whilst keeping the list and replace the form with the new card, ya that's a cool idea.