第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

Django 和 React:錯(cuò)誤消息“您需要啟用 JavaScript 才能運(yùn)行此應(yīng)用程序。”

Django 和 React:錯(cuò)誤消息“您需要啟用 JavaScript 才能運(yùn)行此應(yīng)用程序。”

搖曳的薔薇 2023-06-09 15:04:09
我是 React 的新手,我嘗試讓 Django Rest 和 React 一起工作。順便說(shuō)一句,我的 javascript 已啟用。我有一個(gè)簡(jiǎn)單的看法:class StudentView(generics.ListCreateAPIView):    queryset = Student.objects.all()    serializer_class = StudentSerializer我嘗試從反應(yīng)中獲取它:  useEffect(() =>{    fetch("http://127.0.0.1:8000/secretariat/get_student/", {      method: 'GET',      headers: {        'Content-Type': 'application/json',      }    })    .then( resp => resp.json())    .then( resp => setStudents(resp))    .catch(error => console.log(error))      }, [])當(dāng)我檢查瀏覽器網(wǎng)絡(luò)時(shí),我得到的響應(yīng)是:我不認(rèn)為我有 CORS 標(biāo)頭問(wèn)題,但這是我的 CORS 設(shè)置。INSTALLED_APPS = [    'django.contrib.admin',    'django.contrib.auth',    'django.contrib.contenttypes',    'django.contrib.sessions',    'django.contrib.messages',    'django.contrib.staticfiles',    'django.contrib.sites',    'corsheaders',    'common_app',    'rest_framework',    'rest_framework.authtoken',    'allauth.account',    'rest_auth.registration',    'ldap',    'rest_auth',    'simple_history',]MIDDLEWARE = [    'django.middleware.security.SecurityMiddleware',    'django.contrib.sessions.middleware.SessionMiddleware',    'corsheaders.middleware.CorsMiddleware',    'django.middleware.common.CommonMiddleware',    'django.middleware.csrf.CsrfViewMiddleware',    'django.contrib.auth.middleware.AuthenticationMiddleware',    'django.contrib.messages.middleware.MessageMiddleware',    'django.middleware.clickjacking.XFrameOptionsMiddleware',    'simple_history.middleware.HistoryRequestMiddleware',]CORS_ORIGIN_ALLOW_ALL = FalseCORS_ORIGIN_WHITELIST = (    'http://127.0.0.1')CORS_ALLOW_METHODS = (    'DELETE',    'GET',    'OPTIONS',    'PATCH',    'POST',    'PUT',)CORS_ALLOW_HEADERS = (    'accept',    'accept-encoding',    'authorization',    'content-type',    'dnt',    'origin',    'user-agent',    'x-csrftoken',    'x-requested-with',)我假設(shè)我做錯(cuò)了什么,但我不知道。
查看完整描述

1 回答

?
aluckdog

TA貢獻(xiàn)1847條經(jīng)驗(yàn) 獲得超7個(gè)贊

好吧,我真的不知道為什么,但我讓它與 Axios 一起工作,而根本沒(méi)有改變我的 CORS 設(shè)置。如果有人知道為什么它使用 axios 而不是使用 fetch,我想知道。


因此,如果這里發(fā)生在其他人身上,則工作代碼會(huì)使用 axios 作出反應(yīng):


  axios.get("http://127.0.0.1:8000/secretariat/get_student/")

    .then(response => {

      console.log(response)

      })

    .catch(error => {

      console.log(error);

    })


查看完整回答
反對(duì) 回復(fù) 2023-06-09
  • 1 回答
  • 0 關(guān)注
  • 218 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)