-1

I have a python program which prints a bunch of strings.

My program scrapes house websites through an api, and prints out the house type, bedrooms, location, and a url to an image to the IDE console.

I use PyCharm IDE to print out the results to the console. However, i would like to run this python file online to print these results to a html page rather than the IDE console. My problem is, when i put the file on my web host, and run it, it just shows me the lines of code that are in the python file, instead of actually running it and printing anything out. I have researched 'CGI-BIN', which prints the code as it would on the IDE, however, my web host '000webhost', doesn't include it this capability. I have also researched about web frameworks, such as flask and django.

Is there a way to print to html without web frameworks? if not, then please tell me how to do this through web frameworks.

If the description above is too broad, please comment so that i can add more details rather than voting down my question please.

  • You may want to try a static html page generator. Look here: https://wiki.python.org/moin/StaticSiteGenerator – joel goldstick Mar 21 '16 at 18:13
  • If this is just for debugging, you could forgo the web server and just print to a local file to view with your browser. I do this quite a bit debugging django on the command like (wget/curl/etc). – Tim S. Mar 21 '16 at 18:16
  • You don't specify how complex your desired output is; you could use `print('hello world')`. – msw Mar 21 '16 at 18:22

2 Answers2

1

If you want a static .html file that you can copy by hand to your webhost you can just write to file directly instead of the IDE. Here's a tutorial on writting to files in python, you just need to write proper html structure by hand.

If you need to have a dynamically updated webpage that runs on python backend you need to have your own server (or find one that supports python). The tutorial for this is out of scope for Stack Overflow answer format, but here's a very basic example of deploying Django web framework to production.

Ritave
  • 1,333
  • 9
  • 25
0

On this page the following code was posted which may work for you. (Although the question is about beautiful soup, it seems to be a generic python answer).

import os
import webbrowser

html = '<html> ...  generated html string ...</html>'
path = os.path.abspath('temp.html')
url = 'file://' + path

with open(path, 'w') as f:
    f.write(html)
webbrowser.open(url)`
Community
  • 1
  • 1
Laurel
  • 5,965
  • 14
  • 31
  • 57