N
N
Nikita M.2021-05-10 11:57:33
Django
Nikita M., 2021-05-10 11:57:33

How to call a js script from a Django view in a template?

Under a certain condition, either a redirect is made from the view, or a pop-up needs to be called. The pop-up itself and the pop-up call function are defined in the template. How can such a thing be implemented?
For example:

@login_required
@api_view(['GET', 'POST'])
def client_authentication(request):
    if request.method == 'POST':
        return redirect('login')
    if request.method == 'GET':
        ## здесь вызоваем скрипт определенный в шаблоне

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
soremix, 2021-05-10
@soremix

The request comes through Ajax, as I understand it? In the query constructor, you can immediately define the behavior for a successful query.

success: function() {
    popup();
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question