Iview-admin
main.js
import axios from 'axios';
axios.interceptors.request.use(
config => {
let ttoken = JSON.parse(localStorage.getItem('token'));
if (ttoken !== null) {
config.headers['Authorization'] = 'Token ' + ttoken;
}
return config;
}, function (error) {
return Promise.reject(error);
}
);
axios.defaults.withCredentials = true;
Vue.prototype.$ajax = axios;
logo.vue
提交错误
{{ e }}
Django
settings.py
INSTALLED_APPS = [
'rest_framework',
'rest_framework.authtoken',
'corsheaders',
]
# http://www.django-rest-framework.org/api-guide/permissions/#api-reference
# rest-framework
REST_FRAMEWORK = {
'DEFAULT_AUTHENTICATION_CLASSES': (
'rest_framework.authentication.BasicAuthentication',
'rest_framework.authentication.TokenAuthentication',
'rest_framework.authentication.SessionAuthentication',
),
'DEFAULT_PERMISSION_CLASSES': (
# 'rest_framework.permissions.AllowAny',
'rest_framework.permissions.IsAuthenticated',
)
}
CORS_ALLOW_CREDENTIALS = True
CORS_ORIGIN_ALLOW_ALL = False
CORS_ORIGIN_WHITELIST = (
'localhost:8080',
)
APPEND_SLASH=False
urls.py
from rest_framework.authtoken import views
path('api-token-auth', views.obtain_auth_token),
api.py
from .serializers import AssetSerializer
from rest_framework import permissions
from rest_framework import generics
from django.views.decorators.csrf import csrf_exempt
from rest_framework.pagination import PageNumberPagination
from django.utils.deprecation import MiddlewareMixin
class StandardResultsSetPagination(PageNumberPagination):
page_size = 2
page_size_query_param = 'page'
max_page_size = 1000
class DisableCSRFCheck(MiddlewareMixin):
def process_request(self, request):
setattr(request, '_dont_enforce_csrf_checks', True)
class AssetList(generics.ListCreateAPIView,DisableCSRFCheck):
queryset = AssetLoginUser.objects.all()
serializer_class = AssetSerializer
permission_classes = (permissions.IsAuthenticated,)
pagination_class = StandardResultsSetPagination
class AssetDetail(generics.RetrieveUpdateDestroyAPIView,DisableCSRFCheck):
queryset = AssetLoginUser.objects.all()
serializer_class = AssetSerializer
permission_classes = (permissions.IsAuthenticated,)
pagination_class = StandardResultsSetPagination
网页标题:iview-admin1.3+django2.0(二)用户登录
本文地址:
http://chengdu.cdxwcx.cn/article/ggggco.html