diff --git a/form_demo/urls.py b/form_demo/urls.py index 7da7bde..163717c 100644 --- a/form_demo/urls.py +++ b/form_demo/urls.py @@ -10,4 +10,6 @@ urlpatterns = [ path('userinfomodel/', views.userinfo_model_form), path('userinfomodelsave/', views.userinfo_model_from_save), re_path(r'media/(?P.*)', serve, {'document_root': settings.MEDIA_ROOT}), + path('login/', views.ajax_login), + path('logindata/', views.ajax_login_data) ] diff --git a/form_demo/views.py b/form_demo/views.py index 1a22c20..62bd9ef 100644 --- a/form_demo/views.py +++ b/form_demo/views.py @@ -1,4 +1,5 @@ from django.shortcuts import render +from django.http import JsonResponse from .forms import * @@ -77,3 +78,16 @@ def userinfo_model_from_save(request): print(errors) return render(request, 'form_demo/userinfomodels.html', {'form_obj': f, 'errors': errors}) return render(request, 'form_demo/userinfomodels.html', {'form_obj': f}) + + +def ajax_login(request): + return render(request, 'form_demo/ajax_login.html') + + +def ajax_login_data(request): + username = request.POST.get('username') + password = request.POST.get('password') + if username == 'admin' and password == 'admin123': + return JsonResponse({'code': 1, 'msg': '登录成功'}) + else: + return JsonResponse({'code': 0, 'msg': '登录失败'}) diff --git a/templates/form_demo/ajax_login.html b/templates/form_demo/ajax_login.html new file mode 100644 index 0000000..557b83c --- /dev/null +++ b/templates/form_demo/ajax_login.html @@ -0,0 +1,35 @@ + + + + + Title + +{% csrf_token %} +{% load static%} + + +用户名: +密码: + + + + \ No newline at end of file