Django ajax no refresh:django view without redirecting or refreshing a page

后端 未结 3 494
攒了一身酷
攒了一身酷 2021-01-17 00:29

I\'d like to execute some Python code if that button is pressed on web.The thing is, I need the page not to redirect or refresh or anything.

3条回答
  •  臣服心动
    2021-01-17 01:19

    Just use jQuery ajax,it is easy to do

    in django views.py

    def fun1(request):
        user_input = request.GET.get('value')
        #put your code here
        return HttpResponse('what you want to output to web')
    

    urls.py

    url(r'^link-to-fun1$', views.fun1),
    

    html

    
    
    Your title
    
    
    
    
    

    More see jQuery $.get method

提交回复
热议问题