我们专注攀枝花网站设计 攀枝花网站制作 攀枝花网站建设
成都网站建设公司服务热线:400-028-6601

网站建设知识

十年网站开发经验 + 多家企业客户 + 靠谱的建站团队

量身定制 + 运营维护+专业推广+无忧售后,网站问题一站解决

iview-admin1.3+django2.0(二)用户登录

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://mswzjz.cn/article/ggggco.html

其他资讯