5

I have a python flask application, but I have some old php scripts that I would want to reuse.

I am trying to parse some data from my flask application. When accessing it, company login password is needed, so "curl" in php wouldn't really work. So I am thinking of parsing the data to the php scripts through render_template.

Is it possible to do something like this :

data= <some data>  
@app.route('/test')
def test():
   return render_template('my_php_scripts.php',input_data=data)

While in my php script, I do:

<?php
   $DataString=**{{input_data}}**
?>

If not, what would be a good way to do it?

2
  • I kind of love what you're trying to do here. Commented Feb 10, 2017 at 19:03
  • Researched a bit on my own, It doesn't seem to be possible. Since using flask render_template, it wouldn't be using the php interpreter. So how do people translate old php scripts into python environment? Do they simply rewrite everything? Or is there a way to easily convert them? Commented Feb 10, 2017 at 19:12

1 Answer 1

2

So if you want process the php in python, you'll need to do something like

data = "Charles"
from subprocess import call
call(["php", "my_php_scripts.php", data])

where your php script looks something like

<?php
$DataString = $argv[1];
echo "Eat nachoes, $DataString!\r\n";

presuming the data is something fairly simple, or maybe you can convert it into a JSON if it's a more complex object and transfer it in that way.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.