我使用django-rest-framework在django中实现了一个REST api,并使用oauth2进行身份验证.
我测试过:
curl -X POST -d "client_id=YOUR_CLIENT_ID&client_secret=YOUR_CLIENT_SECRET&grant_type=password&username=YOUR_USERNAME&password=YOUR_PASSWORD" http://localhost:8000/oauth2/access_token/
Run Code Online (Sandbox Code Playgroud)
和
curl -H "Authorization: Bearer <your-access-token>" http://localhost:8000/api/
Run Code Online (Sandbox Code Playgroud)
在localhost上,成功的结果与文档一致.
将其推送到现有AWS弹性beanstalk实例时,我收到:
{ "detail" : "Authentication credentials were not provided." }
Run Code Online (Sandbox Code Playgroud) django amazon-web-services oauth-2.0 django-rest-framework amazon-elastic-beanstalk
是否有一种简单的方法可以修改视图集和路由器的开箱即用链接?
例如,在urls.py中:
from rest_framework import viewsets, routers
...
class Activity_TypeViewSet(viewsets.ModelViewSet):
model = Activity_Type
...
router.register(r'activity_types', Activity_TypeViewSet)
...
url(r'^', include(router.urls)),
Run Code Online (Sandbox Code Playgroud)
这设置了url结构,如:
{"activity_types": "http://odd.quantdevgroup.com/activity_types/"}
Run Code Online (Sandbox Code Playgroud)
问题归结为链接的容易程度:
{"activity_types": "**https**://odd.quantdevgroup.com/activity_types/"}
Run Code Online (Sandbox Code Playgroud)
如果我取消激活http /端口80并且只允许https /端口443,那么我的应用程序需要在无法打开http后因手动将https添加到链接(因为我禁用了端口80).