ajax删除就是在html页面的script里写
getstudent.html
Title
url
from django.conf.urls import urlfrom django.contrib import adminfrom app.views import classesfrom app.views import studentfrom app.views import ajaxurlpatterns = [ url(r'^admin/', admin.site.urls), url(r'^classes.html$',classes.get_classes),#不加^访问点击页面没反应 url(r'^add_classes.html$',classes.add_classes), url(r'^del_classes.html$', classes.del_classes), url(r'^edit_classes.html$',classes.edit_classes), url(r'^set_teacher.html$', classes.set_teacher), url(r'^student$', student.get_student), url(r'^add_student$', student.add_student), url(r'^del_student$', student.del_student), url(r'^edit_student$',student.edit_student), url(r'^ajax1$', ajax.ajax1), url(r'^ajax2$', ajax.ajax2), url(r'^ajax3$', ajax.ajax3), url(r'^ajax4$', ajax.ajax4),]
ajax.py
from django.shortcuts import render,HttpResponsefrom app import modelsdef ajax1(req): return render(req,'ajax1.html')def ajax2(req): user=req.GET.get('username') pwd=req.GET.get('password') import time time.sleep(5) return HttpResponse('你好')def ajax3(req): v1=req.POST.get('a1') v2=req.POST.get('a2') try: v3=int(v1)+int(v2) except Exception as e: v3='格式错误' return HttpResponse(v3)def ajax4(req): nid=req.GET.get('nid') msg='s' try: models.Student.objects.filter(id=nid).delete() except Exception as e: msg=str(e) return HttpResponse(msg)