A
A
Alexander Vinogradov2019-01-22 17:25:04
Django
Alexander Vinogradov, 2019-01-22 17:25:04

How to write a view class that passes data but doesn't reload the page?

When the link is clicked, the id of the object is passed. The link is handled like this:
path('works//', views.WorksIDView.as_view(), name='worksid'),
The view that handles the link should pass the information, but not reload the page.
Info will be processed by JS.
How to create such a class?
For the test, I did this, but even this example loads a different page.

def WorksIDView(request, pk):
    data = { 'images': 'images', 'description': 'description' }
    return JsonResponse(data)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
Y
Yura Khlyan, 2019-01-22
@MAGistr_MTM

1. Js-ohm catch clicking on the link. Stop the events (so that the page does not reload)
2. Inside the click interception function, send ajaxa request to the url
3. Djangomakes logic and sends a response
4. In the same function of sending the request (JS), we receive the data sent Djangoand change what is needed on the page using jQueryor display errors
5. ?????
6. PROFIT!!!!11

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question