astonishing-kilobyte-60820
07/04/2022, 1:32 AMsetattr(request, "session", "session")
messages = FallbackStorage(request)
setattr(request, "_messages", messages)
astonishing-kilobyte-60820
07/04/2022, 1:34 AMgray-morning-3453
07/05/2022, 4:00 AM<div id="calendar"
hx-get="/day/"
hx-vals="js:{date: new Date()}"
hx-target="this"
hx-swap="outerHTML"
hx-trigger="load">
</div>
The get requested is initiated on the client side but without the ``date``querystring parameter appended to it. The same code works on a standalone local page.gray-morning-3453
07/05/2022, 4:06 AMgray-morning-3453
07/05/2022, 6:34 AMgray-morning-3453
07/05/2022, 6:38 AMastonishing-kilobyte-60820
07/05/2022, 11:39 PMastonishing-kilobyte-60820
07/05/2022, 11:45 PMif htmx reuqet .... else render regular view
, see the documentation for more details on how that works.
2) To avoid all the extra urls! You don't need a new endpoint for every single request (edit, delete etc.) instead the htmx requests handle it themselves. (again see documentation for more details)
It also has some built in htmx requests for basic functionality. If you want a delete button, there's a built in htmx request that all you do is pass in the object (to a template tag) that you want to delete and the built in htmx request will handle it for you!
Please take a look at the repo and documentation. https://github.com/yaakovLowenstein/simple-django-htmx
I am open to pull requests if there's anything you can think of adding/ or if any bugs are found!
Thanks!gray-morning-3453
07/06/2022, 7:29 AMgray-morning-3453
07/06/2022, 7:44 AMastonishing-kilobyte-60820
07/07/2022, 12:58 AMastonishing-kilobyte-60820
07/07/2022, 12:59 AMgray-morning-3453
07/07/2022, 4:44 AMgray-morning-3453
07/07/2022, 5:46 PMgreen-napkin-82002
07/07/2022, 11:50 PMblue-ghost-19146
07/08/2022, 3:56 AMhandsome-shampoo-48908
07/08/2022, 8:46 AMhandsome-shampoo-48908
07/08/2022, 8:47 AMhandsome-shampoo-48908
07/08/2022, 8:47 AMhandsome-shampoo-48908
07/08/2022, 8:58 AMhtml
<form method="POST" class="d-flex gap-2 mt-2">
{% csrf_token %}
<input type="text"
name="collection-name"
class="form-control"
placeholder="Enter a new collection ...">
<button class="btn btn-success"
hx-post="{% url 'add-collection' %}"
hx-target="#collections"
hx-swap="beforeend"
type="submit">Add
</button>
</form>
views:
py
def add_collection(request):
collection_name = escape(request.POST.get("collection-name"))
collection, created = Collection.objects.get_or_create(name=collection_name, slug=slugify(collection_name))
if not created:
return HttpResponse("The collection already exists.", status=409)
return render(request, 'tasks/collection.html', context={"collection": collection})
ripe-action-67367
07/08/2022, 9:34 AMhandsome-shampoo-48908
07/08/2022, 9:41 AMhandsome-shampoo-48908
07/08/2022, 9:50 AMambitious-london-57076
07/08/2022, 11:18 AMsilly-bear-76516
07/08/2022, 2:23 PMadmin-posts-partial
have those buttons? You can always inspect using webtools the html that is rendered by the backend on response to the toggleambitious-london-57076
07/09/2022, 5:47 AMblue-ghost-19146
07/09/2022, 2:24 PMbrave-processor-48373
07/09/2022, 3:01 PMblue-ghost-19146
07/09/2022, 3:14 PMbrave-processor-48373
07/09/2022, 3:28 PM