标签:请求 setting 登录 with coding else you img span
from django.http import HttpResponse # Create your views here. a = {"name":"来了老弟","pwd":"老弟你真棒"} #声明全局变量 def indexb(request): if request.method == "POST": name = request.POST.get("name") #post请求 pwd = request.POST.get("pwd") if name == a["name"] and pwd == a[‘pwd‘]: #判断 return HttpResponse("POST登陆成功") else: return HttpResponse("POST登录失败")
post请求需要跨域需要在一级目录下的settings.py文件中写入
下包 pip install django-cors-headers 下面的操作在setting里 添加到appps里 INSTALLED_APPS = [ ... ‘corsheaders‘, ... ] 注释掉csrf并添加‘corsheaders.middleware.CorsMiddleware‘ MIDDLEWARE = [ ‘django.middleware.security.SecurityMiddleware‘, ‘django.contrib.sessions.middleware.SessionMiddleware‘, ‘django.middleware.common.CommonMiddleware‘, # ‘django.middleware.csrf.CsrfViewMiddleware‘, ‘django.contrib.auth.middleware.AuthenticationMiddleware‘, ‘django.contrib.messages.middleware.MessageMiddleware‘, ‘django.middleware.clickjacking.XFrameOptionsMiddleware‘, ‘corsheaders.middleware.CorsMiddleware‘, ] 添加跨域配置 CORS_ALLOW_CREDENTIALS = True CORS_ORIGIN_ALLOW_ALL = True CORS_ORIGIN_WHITELIST = () CORS_ALLOW_METHODS = ( ‘DELETE‘, ‘GET‘, ‘OPTIONS‘, ‘PATCH‘, ‘POST‘, ‘PUT‘, ‘VIEW‘, ) CORS_ALLOW_HEADERS = ( ‘XMLHttpRequest‘, ‘X_FILENAME‘, ‘accept-encoding‘, ‘authorization‘, ‘content-type‘, ‘dnt‘, ‘origin‘, ‘user-agent‘, ‘x-csrftoken‘, ‘x-requested-with‘, ‘Pragma‘, )
标签:请求 setting 登录 with coding else you img span
原文地址:https://www.cnblogs.com/hy-74/p/12074818.html