D
D
Denis Lvov2019-10-18 18:29:16
JavaScript
Denis Lvov, 2019-10-18 18:29:16

How to call a python function via js ajax in django?

Tell me how to spell correctly
. in js i'm a complete zero below can be heresy:
there is an html button:

<button onclick="click()" class="btn">Жмяк</button>

on clicking which, through ajax, there should be a js request:
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js"></script>
<script type="text/javascript">
        function click() {
                    $.ajax({
                        url: 'stat/';
                        success: alert('Оно наконец заработало!');
                    });
    };
</script>

in python files I have in urls.py:
from django.urls import path
from . import views
urlpatterns = [
    path('stat/', views.stat),
]

in views:
def stat(request):
    ''''какой-то мой код''

well here's my dead end

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
monochromer, 2019-10-18
@monochromer

function click() {
  $.ajax({
    url: 'stat/';
    success: function() {
      alert('Оно наконец заработало!')
   }
  })
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question