skip to Main Content

I have been working on a program in python that I want to make available to paid subscribers via REST. I’m currently thinking of having the frontend made in WordPress and then host the backend somewhere else.

In wordpress there are a bunch of plugins to handle paid subscribers and so on and everything seems great but my concern is how do I verify this on the backend that is hosted somewhere else?
If I use Django, is there any way I can make some kind of call to the WordPress server(?) and verify that the user that is trying to fetch items are an paid subscriber?

I made a Diagram to kind of show what I mean. Basically B should only answer back with items if the caller A is a paid subscriber.

I’ve read that it is possible to generate an API key that will be needed in order to fetch data from the API, I’ve also read ways of hiding this call from the frontend to the backend from the user by using some kind of relay on wordpress. Might be wrong here.

Is there any preferred way of doing this?
Is Django REST & WordPress suitable options to do this?

2

Answers


  1. In programming almost anything is possible. However, since wordpress is built in php I would not say that it would be possible to work directly with it. But, (MAYBE) you can connect the wordpress database to django for READ only and create an api.

    How I would do it if I had this task:

    1. Connect Django to an existing db (your wordpress db):

       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.**
      
    2. Since you created the models you can create your endpoints:

      • Create you serializers and viewsets from the models that was auto-generated by django from your wordpress db.
      • Display the data you need such as the user data you need to fetch ex:paid_subscriber = True or paid_subscriber = 1. Certainly it will be there.

    I think the only issue you will have is to connect with the wordpress database. After you have done this in django nothing can stop you to create endpoints with django-rest-framework displaying the data it has.

    Login or Signup to reply.
  2. You can do that using the Django REST framework(DRF) which is used for such purpose for making the rest API’s.

    As per your query i would suggest you to the DRF to read the data from wordpress database and perform the validation on top of it.

    Here are some links that you can use for reference :-

    https://pythonrepo.com/repo/istrategylabs-django-wordpress-python-third-party-apis-wrappers
    https://www.ianlewis.org/en/administer-wordpress-django-admin

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search