Z
Z
zelsky2015-07-03 08:24:01
JavaScript
zelsky, 2015-07-03 08:24:01

Rendering with Ajax in Django?

Multiple queryset in each counter result. Two buttons. So how to display the result by clicking on the button without reloading the page? Where to dig in functions or where?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
Roman Kitaev, 2015-07-03
@zelsky

jQuery.get on the client side.
JSONResponse on the backend side:

from django.http import JSONResponse
from django.views.generic import View
from .models import MyModel

class MyView(View):
    def get(self, request, *args, **kwargs):
        result = {'count': MyModel.objects.count()}
        return JSONResponse(result)

The code has not been tested.

D
Dmitry Shapoval, 2015-07-03
@unkier

there are things ready. e.g. www.dajaxproject.com

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question