Python flask render_template

How to render_template a .php file?

Hi @Louis

In order for the community to suggest ideas to help you solve your code issue it would be useful to share a link to your Repl.

Any error messages that you see appear when you attempt to run your code would also be useful to share here.

1 Like

main.py

from flask import Flask, render_template

app = Flask(__name__)

@app.route('/')
def home():
  return render_template('home.php')

app.run(host='0.0.0.0', port=8080)

templates/home.php

<?php echo "hello" ?>

it will show:

Thanks @Louis

From the screenshot it looks like you have solved this. Can you confirm please or - post a link to your Repl containing the Flask code so we can investigate?

is there any reason you can’t just use a PHP repl as you seem to be doing in the screenshot?
Run in shell:

sed -i "s/];/    pkgs.php\n  &/" replit.nix

Then, in code:

from subprocess import check_output
...
  return check_output(["php", "templates/home.php"])
1 Like

I personally think that python flask can better help me create a website, but I want to use php at the same time

image

:flushed: Edited the command now

@StupidGenius thanks your help :blush:

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.