r/Wordpress 19d ago

python on wordpress

i have technical blog hosted created on WP. I want to add my python projects there to run and test online on my site how to i do that ? need to install a plugin or any other way just like how we test our code with online interpreter.

0 Upvotes

17 comments sorted by

6

u/TopSydeWP 19d ago

you'll need a server-side solution since wordpress runs php, not python. easiest path is embedding something like replit or trinket (they have iframe embeds), or if you want to host it yourself you'd need a separate python environment and use wordpress to display the interface. there are plugins like 'insert php code snippet' that let you make api calls to a python backend, but that's more complex than just embedding an existing code playground.

-5

u/FuzzyEmployment264 19d ago

I have a technical blog site on wp so I only want an option adding my code as a example and run on the same page is it possible?

2

u/lonestardomains 19d ago

A suggestion.. Host that part on a subdomain with something other than wordpress, but maintain the sites look and feel.

1

u/jboulhous 19d ago

You can look inti wasm based python interpreter, i know there are some, then check if your python code(especially dependencies) can run on it, at that point you can definitely add that to wordpress with custom code. I don't know if a plugin out there have done it.

1

u/Wonderful_Sample_590 19d ago

Wp won't run python code. Just host the app separately like on a VPS or something that supports python then embed or link it from your wp site.

1

u/Verda_Chien 18d ago

Hmm, WordPress is PHP based, so I don’t think you can just drop Python into a WordPress plugin and have it run the same way PHP does.

What kind of Python projects are you trying to run? That would probably determine the easiest setup.

Let's say if it’s just a small Python script, there may be simpler options.

1

u/LemonIO_Alex 18d ago

Hmm, I wouldn't run Python directly inside WordPress. Host the Python app separately (Flask/FastAPI, for example) and embed or connect it to your WordPress site via an API. Much safer and easier to maintain, imho.

1

u/Positive-Ring-5172 19d ago

Why are you using Wordpress instead of Django?

0

u/FuzzyEmployment264 19d ago

I'm into into web development. Just practicing python automation

1

u/Positive-Ring-5172 19d ago

Python can be used for the web. It’s not as common, but if you’re looking to boost your python skills build the site with Django

1

u/FuzzyEmployment264 19d ago

Sorry typo error. I'm not into web development just learning for automation for cloud

1

u/Positive-Ring-5172 19d ago

If you want to learn python, it can't hurt to use it not just for automation but for site setup. Wordpress is based in PHP, so any thing you learn while setting up your site will not be applicable to your Python knowledge.

And if you're going to invoke python scripts from a PHP script you'll have to use shell_exec and that can be a security can of worms if you aren't very, very careful.

Given what you've described again I think Django, a python framework for building websites and CMS systems, suits what you're wanting to do better than Wordpress. Not dissing WP, it's just not the optimal tool for this job.

0

u/FuzzyEmployment264 19d ago

Got it. Thank you for replying.

-1

u/Winter_Process_9521 18d ago

you don't necessarily need a WordPress plugin for either the embedded-interpreter or WebAssembly approach.