1. The first problem you need to solve is template rendering. Due to its inherent advantages, PHP does not consider caching. It only needs one sentence to achieve a rendering template without variable pollution.
<?php
call_user_func(function()use($context){
include "your_path_to_template";
});
?>
But Python needs to design a separate template rendering layer. For details, please refer to Django (ps is the template layer! Don't make a mistake to see the implementation of Django's View layer. His various mixed-in class multiple inheritance has driven me crazy).
2. You need to determine whether you are implementing WordPress functions or translating the WordPress logic completely with Python. WordPress was developed many years ago. At that time, there was no MVC in PHP at all, so you can see that WP is playing with hooks. Most modern CMSs are multi-layered architectures, such as PHPCMS.
3. If you just want to simply translate WP with Python, you can just follow the WordPress source code to translate WP with Python, which is not difficult at all.
Of course, if you really do this, I think as the code gets more and more, you will soon crash.
So I assume that you just want to implement the functions of WordPress (not copy them):
3.1. You need to implement your own model layer, view layer, and control layer. Before that, in order to coordinate the loading of your Python code, you also need to write a simple route. Due to Python's elegant package design, you don't need to implement your own loading function like early PHP. This requires too much code.
3.2. The control layer base class has nothing to say, it is very simple, except for the specific logic part, the function is to combine the model object and the view object.
3.3. In the model layer, you need to design your own ORM. Since WP was written a long time ago, if you copy his database code, you will regret it. Considering that there is no such thing as the PDO module that comes with PHP in the Python annotation library, you need to use a third-party package or design a set of things similar to SQLAlchemy.
3.4. See Article 1 for the view layer. But you have to design some helper functions, such as helper functions (methods) for generating forms, generating images, generating HTML code, and loading header, main, and footer files. This is not difficult, these implementations with PHP do not exceed 100 lines. If you don't need a third-party library for Python, please ask yourself.
4. After completing the basic design above, you can concentrate on translating the WordPress functions with Python, disassemble the various functional modules such as content management, membership management, permission management, and point management, and realize (translation) bit by bit. This part is the key point. You need to be patient and read the source code. Of course, you will be distracted to familiarize yourself with the data sheet of WP. However, due to the previous modular design, it will certainly not feel confusing.
5. The last thing I want to say is that the front-end parts above are all independent modules, which are of course easy to handle. What may cause confusion is how to implement the combination of these modules, such as background management. I was so confused at first! How to fit so many plug-ins perfectly and better? Then the more I thought about it, the more I dared not to code for a while. Later, I felt that there was no need to think so much. Because I found that PHPCMS is also simple to embed other view layers in an iframe in the template of amin. Of course, you can also choose to use Ajax technology.
Finally, don’t forget the Python philosophy: Keep it Stupid Simple, it’s really scary to have such a big goal.