简体   繁体   English

在本地运行Nuxt项目时,如何登录和访问我的Django-Rest-Framework?

[英]How can I login and access to my Django-Rest-Framework while running my Nuxt project local?

I use Django-Rest-Framework for my API. 我为我的API使用Django-Rest-Framework。 It is on a remote server in the internet. 它位于互联网上的远程服务器上。

Locally I have a Nuxt-JS application running which should consume the REST-API. 在本地我运行的Nuxt-JS应用程序应该使用REST-API。

How can I access this API from my local machine? 如何从本地计算机访问此API?

1) I would like to get the CSRF token from my login page with axios. 1)我想从axios的登录页面获取CSRF令牌。 For example from: /accounts/login/ For this I would like to make a "GET" call and geht from the HTTP-HEADER my CSRF tocken. 例如来自:/ accounts / login /为此,我想从HTTP-HEADER我的CSRF tocken进行“GET”调用。 But how? 但是怎么样?

You can install @nuxt/auth module after which you can update your nuxt.config.js file as follows: 您可以安装@ nuxt / auth模块,之后您可以更新nuxt.config.js文件,如下所示:

auth: {
   redirect: {
      login: 'your-login-redirect-path',
      logout: 'your-logout-redirect-path',
      home: 'your-home-path'
   },
   strategies: {
      local: {
         endpoints: {
            login: { url: 'your-django-login-endpoint', method: 'post', propertyName: 'token' },
            logout: { url: 'your-django-logout-endpoint', method: 'post' },
            user: { url: 'your-django-userinfo-endpoint', method: 'get', propertyName: 'user' }
         }
      }
   }
},

Check out Nuxt Auth for more info 查看Nuxt Auth了解更多信息

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何从我的 nuxt js 组件中的 node_modules 文件夹动态加载 svg 图标? - How can I dynamically load svg icons from node_modules folder in my nuxt js component? VueJS-无法通过登录POST从Django Rest Framework获取用户令牌 - VueJS - can't get user token from Django Rest Framework via login POST 如何解决每次更改 api 时都需要在 nuxt 中重新加载 api 的问题? - How to fix needing to reload my api in nuxt every time i change my api? 如何在 col 的 vue js 项目中显示我从 api 拍摄的照片? - How can I show the photos I took from api in my vue js project in col? 如何从连接在同一网络中的任何其他计算机或移动设备访问由 npm 运行服务器命令运行的 vue 项目? - How can I access vue project which is running by npm run server command from any other computer or mobile that is connected in the same network? 如何从Vue JS项目的文件夹中导入JS文件? - How can I import a JS file from a folder in my Vue JS project? 如何在我的 Vue.js 项目中以横向模式打印 html 页面 - How can I print html page in Landscape mode in my Vue.js project 如何解决运行 create-nuxt-app 的此错误? - How do I resolve this error running create-nuxt-app? 如何检查我的 create-nuxt-app 版本并升级它? - How to check my create-nuxt-app version and upgrade it? 如何在方法运行时更新 DOM? - How can I update DOM while a method is running?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM