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;
提交錯(cuò)誤
{{ e }}
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
from rest_framework.authtoken import views
path('api-token-auth', views.obtain_auth_token),
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
另外有需要云服務(wù)器可以了解下創(chuàng)新互聯(lián)scvps.cn,海內(nèi)外云服務(wù)器15元起步,三天無(wú)理由+7*72小時(shí)售后在線,公司持有idc許可證,提供“云服務(wù)器、裸金屬服務(wù)器、高防服務(wù)器、香港服務(wù)器、美國(guó)服務(wù)器、虛擬主機(jī)、免備案服務(wù)器”等云主機(jī)租用服務(wù)以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡(jiǎn)單易用、服務(wù)可用性高、性價(jià)比高”等特點(diǎn)與優(yōu)勢(shì),專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應(yīng)用場(chǎng)景需求。
網(wǎng)站的建設(shè)創(chuàng)新互聯(lián)專注網(wǎng)站定制,經(jīng)驗(yàn)豐富,不做模板,主營(yíng)網(wǎng)站定制開(kāi)發(fā).小程序定制開(kāi)發(fā),H5頁(yè)面制作!給你煥然一新的設(shè)計(jì)體驗(yàn)!已為成都PE包裝袋等企業(yè)提供專業(yè)服務(wù)。