我一直在用 python 開發一個程式,我想通過 REST 將它提供給付費訂閱者。我目前正在考慮在 Wordpress 中制作前端,然后在其他地方托管后端。
在 wordpress 中有一堆插件來處理付費訂閱者等等,一切似乎都很好,但我擔心的是如何在其他地方托管的后端驗證這一點?如果我使用 Django,有什么辦法可以對 Wordpress 服務器進行某種呼叫(?)并驗證嘗試獲取專案的用戶是付費訂閱者嗎?
我做了一個圖表來展示我的意思。基本上,如果來電者 A 是付費訂閱者,B 應該只回復專案。
我已經讀到可以生成一個 API 密鑰,以便從 API 獲取資料所需的 API 密鑰,我還閱讀了通過使用某種方式將這個呼叫從用戶的前端隱藏到后端的方法在 wordpress 上中繼。這里可能是錯的。
有沒有首選的方法來做到這一點?Django REST 和 Wordpress 是否適合執行此操作?
uj5u.com熱心網友回復:
在編程中幾乎任何事情都是不可能的。但是,由于 wordpress 內置于 php 中,因此我不會說可以直接使用它。但是,(可能)您可以將 wordpress 資料庫連接到 django for READ only 并創建一個 api。
如果我有這個任務,我會怎么做:
將 Django 連接到現有資料庫(您的 wordpress 資料庫):
- Django 本身會教您如何從其檔案中連接舊資料庫。
Django comes with a utility called inspectdb that can create models by introspecting an existing database. You can view the output by running this command: $ python manage.py inspectdb Save this as a file by using standard Unix output redirection: $ python manage.py inspectdb > models.py **This feature is meant as a shortcut, not as definitive model generation.**由于您創建了模型,因此您可以創建端點:
- 從 django 從 wordpress 資料庫自動生成的模型中創建序列化程式和視圖集。
- 顯示你需要的資料,比如你需要獲取的用戶資料 ex:
paid_subscriber = Trueorpaid_subscriber = 1. 肯定會有的。
我認為您將遇到的唯一問題是與 wordpress 資料庫連接。在 django 中完成此操作后,沒有什么可以阻止您創建詳細說明其擁有的資料的端點。
uj5u.com熱心網友回復:
您可以使用Django REST 框架 (DRF)來做到這一點,該框架用于制作其余 API。
根據您的查詢,我建議您到 DRF 讀取 wordpress 資料庫中的資料并在其上執行驗證。
以下是一些您可以參考的鏈接:-
https://pythonrepo.com/repo/istrategylabs-django-wordpress-python-third-party-apis-wrappers https://www.ianlewis.org/en/administer-wordpress-django-admin
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/318317.html
標籤:Python 姜戈 WordPress的
