Hello @ThreeMovesAhead , welcome to the forums!
You can try this:
from flask import Flask
app = Flask(__name__)
@app.route('/hello')
def hello_world():
page=open('index.html','r') # opens a file called index.html
return page # displays the file
page.close() # closes the file
if __name__ == '__main__':
app.run('0.0.0.0', 5000)
With this code, you can display a file called index.html, linked to the app route āHelloā.
Hope this helps!
(If your problem is solved, you can mark this post as a Solution)
page.close() never gets called. Also, thatās not what they wanted to do.
Yes. If you want to make a request to ā/helloā from the client side of the host website, you can do something like this in your javascript: (This doesnāt require the repl to be embedded in it)
Iām aware that replit does create a public url for your flask instance if you set host to ā0.0.0.0ā, but what Iām trying to achieve is specifically:
My understanding is, when a user runs an embedded replit, a new instance is created for them. I want the host website to be able to communicate with that specific instance.
Could you be more specific on what you mean by embedding the repl? (e.g. do you mean accessing it from the cover page, embedding the public url with an iframe on another website, or embedding the cover page on a website?)
You are correct that when you run a console repl (one that does not have a webserver) from its cover page on replit.com, a new instance (āghost forkā) is created for them.
However, your repl has a web server, so a new instance is not created for each user, regardless of whether they access it via the cover page, direct url, or embed from another site.
Essentially, all users of a repl with a web server are interacting with the same instance of the web server.
No, this isnāt possible, because you donāt control the webpage returned by <my_replit_url> (Iām assuming itās something of the form replit.com/@ThreeMovesAhead/repl-name.), and afaik replit doesnāt offer a way of interacting with repls using frame messaging.
What exactly are you trying to do? There might be another way that doesnāt involve passing messages to a ghost fork
It might be easier to have the python code in the same repl as the host website. You can send a network request to a web server running on the repl and have it execute python code there
Nice suggestion. Iāll mark it as the solution for replit users, though I ultimately just went with pyodide (makes it possible to run python in browser)