我的 django 服務器在 ssh 客戶端(ubuntu)中運行,但我想在本地視窗機器中測驗 api。我怎么能做到這一點?
uj5u.com熱心網友回復:
如果您的 Web 應用程式是托管的(具有像http://www.stackoverflow.com這樣的域名 ),請使用郵遞員中的 url。
如果您的 web 應用程式尚未部署在某些網路服務器(apcahe、nginx gunicorn 等)中
在服務器IP中公開運行django應用程式如下
python manage.py runserver 0.0.0.0:8000 // make sure port 8000 is open or use an open port.
還可以使用以下命令(在 shell 中)找到您的 ubuntu 的 IP 地址
ifconfig
使用您在郵遞員(Windows)中獲得的IP地址
eg: if the IP address got is 90.101.111.25,
API endpoint: api/user/
method : POST
在郵遞員客戶端
use the url: 90.101.111.25/api/user/
select method : POST
Next you need to provide the Authorization ( to make sure only guanine users access your API).
在 postman 中選擇 Authorization 選項卡,然后選擇您的 Web 應用程式支持的授權(Digest Auth、Basic、Token)。
如果您使用令牌身份驗證,請找到創建的(其中一個)用戶的令牌,并在郵遞員中使用它。
Select Headers and add the following
key: Authorization
value: Token:<space>the-token-generated-by-django-in-the-db
檢查以下內容以在 django(django-rest) 中實作基于令牌的身份驗證。
https://www.django-rest-framework.org/api-guide/authentication/
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/360205.html
