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