bigskysoftware/intercooler-js

simple Django - Intercooler.js example on how to pass a django variable to a view

beanben opened this issue · 2 comments

Hello hello,
Could you please provide a simple example on how intercooler.js could pass a django variable to. view ?

I went as far as :

(a) the template:

<form id="defaults">
  <input name="csrfmiddlewaretoken" type="hidden" value="{{ csrf_token }}">
</form>
<button ic-post-to="{% url 'habitap:click' %}?click_value={{clicks}}" ic-include="#defaults">{{clicks}}</button>

(b) the view:

def click(request):

    clicks = request.POST.get('click_value', 0)
    clicks = clicks + 1
    context = {'clicks': clicks}

    template = Template("{{clicks}}")
    request_context = RequestContext(request, context)

    return HttpResponse(template.render(request_context))

at the moment, all the view is able to do is render 1. I'm tying to create a view that would generate a button with a number incrementing by 1 every time the user clicks.

1cg commented

Hi Ben,

I responded over in the gitter channel, closing this out.

Thanks a ton !!