Ask coding questions

← Back to all posts
Mixing languages in one repl
iiap623616 (1)

Hi,
I was wondering if it is possible to run more than one language in one and the same repl.
For example, I would like to generate an html+javascript page using Python, and then be able to run that page just like I do in an HTML repl.
If I create a Python repl for example, there is no way to run the HTML file - even if I have it in that repl.
Thank you in advance for the clarification.
Eugene.

Answered by mat1 (2728) [earned 5 cycles]
View Answer
Commentshotnewtop
mat1 (2728)

You can use Flask to create web servers using Python.
Flask's official documentation is here but you could also look at my quick example at https://repl.it/@mat1/Flask-example.
Please upvote this comment if it was helpful or useful in any way

iiap623616 (1)

@mat1 This will likely be my next step. But for now I am looking for a way to just do that -- generate an HTML file and then open it in a browser. Ideally, I would have everything in one environment (like a directory), all of it being online (not having to install anything locally).
Thank you!
Eugene.

XavierDD (63)

@iiap623616 with flask you can generate your file then use

from flask import Flask, render_template
 
app = Flask(__name__)
 
@app.route('/<string:page_name>/')
def render_static(page_name):
    return render_template('%s.html' % page_name)
 
if __name__ == '__main__':
    #Html stuff generator.
    app.run()
iiap623616 (1)

@mat1 Yes, thank you! I got it to work - thanks to your example!
One confusing part was the "_.py" file, but now it works!
Eugene

pyelias (918)

If you specifically want to create html+js in Python, you can use a framework like Flask or Django to create a webserver.

HappyFakeboulde (213)

You could pick the language of the script that starts the whole thing and then put other programs from other languages in the repl which are run by the main file