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

    bumpy-portugal-30413

    12/13/2021, 9:56 PM
    From the user perspective, do you want the browser to redirect to a new page or do you just want to replace the whole page content but not necessarily redirect?
  • f

    fast-baker-86727

    12/13/2021, 9:58 PM
    Right, a new page, the former
  • b

    bumpy-portugal-30413

    12/13/2021, 9:59 PM
    ah yea, I think I misunderstood initially. Probably do need this header then. I guess give it a shot with that url and see
  • w

    worried-nest-35606

    12/14/2021, 9:49 AM
    django template question, unrelated to HTMX. Sorry if this is too far off-topic: I use Baptiste Darthenay's Django extension for template autocomplete. VS Marketplace Link: https://marketplace.visualstudio.com/items?itemName=batisteo.vscode-django does anyone know if it's possible to get autocomplete of the django python variable names in the django-html file?
  • w

    worried-nest-35606

    12/14/2021, 9:50 AM
    From the official django tutorial:
    Copy code
    {% if latest_question_list %}
    <ul>
      {% for question in latest_question_list %}
      <li><a href="/polls/{{ question.id }}">{{ question.question_text }}</a></li>
      {% endfor %}
    </ul>
    {% else %}
    <p>No polls are available.</p>
    {% endif %}
  • w

    worried-nest-35606

    12/14/2021, 9:51 AM
    I would want autocomplete for
    latest_question_list
    ,
    question
    , etc.
  • w

    worried-nest-35606

    12/14/2021, 9:58 AM
    Seems like I might want this, but I'm over my head at the moment. https://docs.djangoproject.com/en/4.0/howto/custom-template-tags/
  • h

    hundreds-camera-24900

    12/14/2021, 6:17 PM
    @User here's how I handled that : https://github.com/gone/animelister/blob/component/animelister/home/views.py#L107
  • h

    hundreds-camera-24900

    12/14/2021, 6:18 PM
    I tried the redirect approach first as well
  • n

    nutritious-dress-29138

    12/15/2021, 2:29 AM
    love that Django get's it's own channel. I am also using HTMX with Django.
  • b

    bumpy-portugal-30413

    12/15/2021, 4:35 AM
    This would update the whole body with the response rather than refreshing right? That's what I was going to suggested via hx-target-oob - but he said he wanted the full refresh
  • h

    hundreds-camera-24900

    12/15/2021, 5:06 AM
    oh if you want a refresh then just use HX-Refresh
  • s

    salmon-xylophone-28580

    12/16/2021, 6:25 PM
    1. I want to serve htmx via django+whitenoise (not via public CDN). 2. I don't want to store htmx in my git repo (which contains python/django code). It should be part of the set-up process. 3. At the moment it is about the set-up of the development environment. How do you do this?
  • j

    jolly-kite-167

    12/16/2021, 10:48 PM
    Add it to your
    package.json
    file and install it via
    npm
    as part of your set-up?
  • s

    salmon-xylophone-28580

    12/17/2021, 8:00 AM
    This works fine, if there is no indirection. With other words: Imagine there is a python/django plugin which needs a special JS library. I install the plugin via pip from a custom pypi server.
  • j

    jolly-kite-167

    12/17/2021, 3:48 PM
    So, you're looking for a python package that you could install that includes the HTMX JS library?
  • s

    salmon-xylophone-28580

    12/17/2021, 4:40 PM
    This would be one solution to solve this. Somehow it does not work out that every language brings its own dependency management. ... I was just curious. Maybe someone has found a solution to this. Bazel (Google build tool) could get used. But maybe this is too much overhead.
  • j

    jolly-kite-167

    12/17/2021, 4:45 PM
    Yeah, I'm afraid that's just the state of things these days. the HTMX library, however, is dependency free (per the home page), unless you're doing development of HTMX itself. https://github.com/bigskysoftware/htmx/blob/master/package.json
  • j

    jolly-kite-167

    12/17/2021, 4:46 PM
    So, you should be able to find a way to include it without installing the universe.
  • s

    salmon-xylophone-28580

    12/17/2021, 4:47 PM
    That's ok. From time to time I like to ask basic questions to check if I missed a cool new way to solve old problems. Thank you
  • j

    jolly-kite-167

    12/17/2021, 4:50 PM
    Any problem that stays a problem long enough is usually not worth solving or is at least NP-hard 🙂
  • m

    melodic-translator-29773

    12/20/2021, 6:42 AM
    hello people I have a question. I have been trying to implement a form where I have to enter a ManyToMany field, and I don't have a clear idea of ​​how I can implement it. In the normal way, I first make a JSON with all the data I need and send it to an API with DRF. But I'm not sure how using HTMX can achieve the same results. thanks for advance 🙂
  • l

    limited-diamond-93357

    12/20/2021, 10:24 AM
    @User So let me try to decode what you said. At the moment, you're using DRF in Django to provide an API, and this API is called by code running in the web browser. That API returns JSON with the data your client code needs.
  • l

    limited-diamond-93357

    12/20/2021, 10:30 AM
    So, you remember from the Django tutorial where your page template has something like this? https://docs.djangoproject.com/en/4.0/topics/forms/#the-template
  • l

    limited-diamond-93357

    12/20/2021, 10:31 AM
    Copy code
    <form action="/your-name/" method="post">
        {% csrf_token %}
        {{ form }}
        <input type="submit" value="Submit">
    </form>
  • l

    limited-diamond-93357

    12/20/2021, 10:32 AM
    You put that (and pretty much just that) in an HTML file which many call a "fragment" or a "partial".
  • l

    limited-diamond-93357

    12/20/2021, 10:33 AM
    In your page code HTML template, you {% include %} that fragment, and that's how the form shows up on your page.
  • l

    limited-diamond-93357

    12/20/2021, 10:33 AM
    You're likely to have your own way of iterating over the fields in the form. I've used
    {{ form }}
    here as a lazy shortcut.
  • l

    limited-diamond-93357

    12/20/2021, 10:35 AM
    On the submit button, you'll add htmx tags so that when the user hits submit. The form data gets sent to your Django view. This Django view should return render() of the fragment, ie, what's returned is HTML, and the HTML is only for the form. htmx will then replace the old form with the new form.
  • l

    limited-diamond-93357

    12/20/2021, 10:35 AM
    It's more complex than that, but that's the short version
1...252627...100Latest