https://htmx.org logo
Join Discord
Powered by
# 🔥-django-htmx
  • m

    modern-doctor-63477

    04/29/2022, 12:49 AM
    Solved this without learning anything
  • m

    mysterious-toddler-20573

    04/29/2022, 2:18 AM
    o_0
  • f

    few-vegetable-15970

    04/30/2022, 2:08 AM
    This is so beautiful...
  • h

    happy-microphone-42295

    05/02/2022, 1:59 PM
    hi all the community. Doing my first steps with a frontend working with django... I have seen a lot of tutorials of vuejs, react js and then i found htmx ... Very quickly i can make a one page app. My intention here is to learn, doing first simple apps with django and htmx and continue learning. Regards from Buenos Aires, Argentina.
  • h

    hundreds-camera-24900

    05/02/2022, 2:14 PM
    yes you can pretty quickly build something w/ django and htmx
  • w

    white-motorcycle-95262

    05/02/2022, 2:20 PM
    Looking at doing something like https://htmx.org/examples/value-select/ but utilizing the power of Django Forms. In my form, I can add a keyword in the
    __init__
    and filter one of my
    ModelChoiceFields
    there. This would result in a reduced select. Anyone know the "Django way" of just getting one fields HTML in a view? Based on being able to do
    {{ form.field_name }}
    in the template, I found I can do the following in a view:
    Copy code
    def my_htmx_endpoint(request)
      form = MyForm()
      html = str(form['field_name'])
      response = HttpResponse(html)
      return response
    But is there something "better" I should be doing, perhaps with the
    render
    shortcut?
  • h

    hundreds-camera-24900

    05/02/2022, 2:36 PM
    you cannot render a field, just a form or a widget
  • h

    hundreds-camera-24900

    05/02/2022, 2:36 PM
    it is upsetting
  • h

    hundreds-camera-24900

    05/02/2022, 2:36 PM
    I have a long polemic on the django discord contributor channel about it
  • h

    hundreds-camera-24900

    05/02/2022, 2:36 PM
    they closed a bug about it
  • h

    hundreds-camera-24900

    05/02/2022, 2:37 PM
    What you have is basically the widget render - I would suggest making a "input group" snippet
  • h

    hundreds-camera-24900

    05/02/2022, 2:37 PM
    here's mine
  • h

    hundreds-camera-24900

    05/02/2022, 2:37 PM
    https://github.com/Lightmatter/generic-django-conf/blob/develop/%7B%7Bcookiecutter.repo_name%7D%7D/%7B%7Bcookiecutter.repo_name%7D%7D/templates/django/forms/inputgroup.html
  • h

    hundreds-camera-24900

    05/02/2022, 2:37 PM
    https://github.com/Lightmatter/generic-django-conf/blob/develop/%7B%7Bcookiecutter.repo_name%7D%7D/%7B%7Bcookiecutter.repo_name%7D%7D/templates/django/forms/default.html
  • h

    hundreds-camera-24900

    05/02/2022, 2:38 PM
    and then using render to string (https://docs.djangoproject.com/en/4.0/topics/templates/#django.template.loader.render_to_string)
  • w

    white-motorcycle-95262

    05/02/2022, 2:38 PM
    hmm, can you illuminate the difference between widget and field? Seems my solution does what I want it to
  • h

    hundreds-camera-24900

    05/02/2022, 2:39 PM
    I think your solution is fine if it's working
  • h

    hundreds-camera-24900

    05/02/2022, 2:39 PM
    the difference is a field contains of the input itself, a label, help text and error text
  • h

    hundreds-camera-24900

    05/02/2022, 2:39 PM
    a widget is just the input
  • h

    hundreds-camera-24900

    05/02/2022, 2:40 PM
    you're basically calling the widget's render
  • w

    white-motorcycle-95262

    05/02/2022, 2:40 PM
    Oh, right. Gotcha.
  • h

    hundreds-camera-24900

    05/02/2022, 2:40 PM
    if all you need is the input then that's great
  • w

    white-motorcycle-95262

    05/02/2022, 2:40 PM
    Right, since I'm just replacing the widget, I suppose there's no way to provide error text sand such.
  • w

    white-motorcycle-95262

    05/02/2022, 2:41 PM
    Which is okay in my case since there's really no way to have an error due to the nature of chained drop downs
  • w

    white-motorcycle-95262

    05/02/2022, 2:41 PM
    Gotcha, thanks for the heads up 🙂
  • h

    hundreds-camera-24900

    05/02/2022, 2:44 PM
    gl 🙂
  • f

    few-vegetable-15970

    05/02/2022, 4:49 PM
    This is most simple and natural thing I could came up with to refactor existing CBV.
  • f

    few-vegetable-15970

    05/02/2022, 4:51 PM
    It is really easy to use, you just have to split correctly your templates and use
    include
    accordingly. Your opinions?
  • h

    hundreds-camera-24900

    05/02/2022, 7:54 PM
    This is how I did it:
  • h

    hundreds-camera-24900

    05/02/2022, 7:54 PM
    https://github.com/gone/animelister/blob/master/animelister/util/views.py#L6
1...585960...100Latest