Answer the question
In order to leave comments, you need to log in
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. Js-ohm catch clicking on the link. Stop the events (so that the page does not reload)
2. Inside the click interception function, send ajax
a request to the url
3. Django
makes logic and sends a response
4. In the same function of sending the request (JS), we receive the data sent Django
and change what is needed on the page using jQuery
or display errors
5. ?????
6. PROFIT!!!!11
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question