-->
www.sychzs.cn
from django.conf.urls import url
from django.contrib import admin
from app01 import views
urlpatterns = [
url(r'^admin/', admin.site.urls),
url(r'^$',views.index),
url(r'^upload_file/$',views.upload_file)
]
www.sychzs.cn
from django.shortcuts import render,HttpResponse
from app01 import models
from django.http import JsonResponse
# Create your views here.
def index(request):
return render(request,'index.html')
def upload_file(request):
'''文件上传'''
import json
dic = {'status':100,'msg':None}
if request.method == 'POST':
# post形式上传json格式数据,POST中没有值,在body中取出
upload_dic = json.loads(request.body)
name = upload_dic['name']
pwd = upload_dic['pwd']
user = models.User.objects.filter(name=name,pwd=pwd).first()
if user:
dic['msg'] = '登陆成功'
else:
dic['status'] = 101
dic['msg'] = '账号或密码错误'
# 这里注意返回一定是Json格式返回
return JsonResponse(dic)
index.html
ajaxAjan实现json格式的数据传输
用户名:
密码:
-->