我的 django 服務器在 ssh 客戶端(ubuntu)中運行,但我想在本地窗口機器中測試 api。我怎麼能做到這一點?
如果您的 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/
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句