0

I am currently trying to create a website that displays a python file (that is in the same folder as the html file) on the website, but I'm not sure how to do so. So I just wanted to ask if anyone could describe the process of doing so (or if its even possible at all).

  • So you just want to display the contents of the Python file on a webpage? – xyres Mar 18 '20 at 14:29
  • I want to display the output yeah. – WeebTendo Mar 18 '20 at 14:29
  • Does this answer your question? https://stackoverflow.com/questions/48552343/how-can-i-execute-a-python-script-from-an-html-button/48552490 – Gamopo Mar 18 '20 at 14:31
  • @WeebTendo Yes, you can do that but since browsers can't run Python code, you'll have to "serve" the script's output from a python server. – xyres Mar 18 '20 at 14:34
  • So with that being the case there wouldn't be a way to do so with simply launching the page locally with the file and python's scripting installed? – WeebTendo Mar 18 '20 at 14:45
  • @WeebTendo Right. Python code can only run in a python process. So you need a way to get the output from the script to the web page. That's where the HTTP server comes in. – xyres Mar 19 '20 at 00:05

2 Answers2

0

Displaying "a python file" and displaying "the output" (implied "of a python script's execution) are totally different things. For the second one, you need to configure your server to run Python code. There are many ways to do so, but the two main options are

1/ plain old cgi (slow, outdated and ugly as f..k but rather easy to setup - if your hosting provides support for it at least - and possibly ok for one single script in an otherwise static site)

and

2/ a modern web framework (flask comes to mind) - much cleaner, but possibly a bit overkill for one simple script.

In both cases you'll have to learn about the HTTP protocol.

bruno desthuilliers
  • 75,974
  • 6
  • 88
  • 118
-1

You can use any WYSIWYG editor with syntax highlighting. I am using CKEditor. Use this link for read documentation https://ckeditor.com/docs/ckeditor5/latest/index.html.

user3804427
  • 432
  • 2
  • 12