https://htmx.org logo
Join DiscordCommunities
Powered by
# 🔥-django-htmx
  • a

    ambitious-london-57076

    11/07/2021, 8:32 PM
    Django view.py
  • a

    ambitious-london-57076

    11/07/2021, 8:36 PM
    Django html template
  • a

    ambitious-london-57076

    11/07/2021, 8:37 PM
    Based on my backend, is there anyone that can suggest how I can swap the image/icon based on whether a person has bookmarked an obj?
  • g

    gorgeous-airport-54386

    11/07/2021, 9:08 PM
    If you swap the whole item when you add/remove a bookmark, then the image should change too, right?
  • b

    bitter-dog-98292

    11/07/2021, 9:08 PM
    @User For that, I would use alpinejs or an equivalent as well as htmx
  • g

    gorgeous-airport-54386

    11/07/2021, 9:10 PM
    @User what currently happens when you click the button? Let's figure out why the image doesn't change
  • a

    ambitious-london-57076

    11/07/2021, 9:11 PM
    Thanks for your response guys, Currently, everything disappears
  • b

    bitter-dog-98292

    11/07/2021, 9:11 PM
    For sure
  • b

    bitter-dog-98292

    11/07/2021, 9:11 PM
    You return an httpresponse
  • b

    bitter-dog-98292

    11/07/2021, 9:11 PM
    you need to return html
  • a

    ambitious-london-57076

    11/07/2021, 9:11 PM
    So the text and the icon is gone. I think it is due to the way I have set up the response. I am not sure what is correct.
  • g

    gorgeous-airport-54386

    11/07/2021, 9:11 PM
    Your response needs to contain the whole
    ul
  • b

    bitter-dog-98292

    11/07/2021, 9:11 PM
    Yep
  • a

    ambitious-london-57076

    11/07/2021, 9:11 PM
    ohhh
  • g

    gorgeous-airport-54386

    11/07/2021, 9:11 PM
    from the template
  • b

    bitter-dog-98292

    11/07/2021, 9:12 PM
    @User Basically what you need to understand with htmx is that your django routes needs to return html
  • b

    bitter-dog-98292

    11/07/2021, 9:12 PM
    Just like you return JSON when you develop a "classic" API queried by a frontend
  • a

    ambitious-london-57076

    11/07/2021, 9:13 PM
    I will try that now
  • a

    ambitious-london-57076

    11/07/2021, 9:14 PM
    Do i put it in qoutes in the httpresponse?
  • g

    gorgeous-airport-54386

    11/07/2021, 9:17 PM
    You can put the ul in a partial. Then, render that partial the same way as any html template
  • g

    gorgeous-airport-54386

    11/07/2021, 9:19 PM
    in your html template:
    Copy code
    {% include "booqmarqed_area.html" %}
    in your view:
    Copy code
    return render(request, 'booqmarqed_area.html')
  • a

    ambitious-london-57076

    11/07/2021, 9:19 PM
    That makes sense
  • a

    ambitious-london-57076

    11/07/2021, 9:20 PM
    Does the button hx logic look correct?
  • g

    gorgeous-airport-54386

    11/07/2021, 9:20 PM
    or however you render a template, i don't know django
  • g

    gorgeous-airport-54386

    11/07/2021, 9:20 PM
    Looks good to me, but
    hx-trigger=click
    is redundant since it's a button
  • a

    ambitious-london-57076

    11/07/2021, 9:24 PM
    And should I swap outerHTML?
  • g

    gorgeous-airport-54386

    11/07/2021, 9:27 PM
    Yes, the response includes the whole list so it should swap the whole list, not just the contents. If you used innerhtml, the list would get another nested list every time you clicked the button
  • a

    ambitious-london-57076

    11/07/2021, 9:27 PM
    Thanks again.
  • a

    ambitious-london-57076

    11/07/2021, 9:27 PM
    I have loaded the as a partial and it all loads well.
  • a

    ambitious-london-57076

    11/07/2021, 9:28 PM
    but I am still not sure what I should write in the HTML response in the django response
1...151617...100Latest