Forums

Displaying Python variables on a website

Hello,

I am new to Python and pythonanywhere. I'm trying to create a simple web app that will update a Tableau datasource via an API. So first, I need to make sure my web app is connecting to Tableau.

I created a pythonanywhere web app with the manual setup using Python 3.6 in a virtual environment. You can see the results at hopemission.pythonanywhere.com.

The Python code that connects to Tableau seems to be working. It gives me a variable called hopemission_info. The end of the code is below. How do I get the variable to show up in the website display?

test = hopemission_info.json()
HELLO_WORLD = """<html>
<body>
<h1>Hello, World!</h1>
<p>
    This is the default welcome page.
</p>
</body>
</html>"""
def application(environ, start_response):
    if environ.get('PATH_INFO') == '/':
        status = '200 OK'
        content = HELLO_WORLD
    else:
        status = '404 NOT FOUND'
        content = 'Page not found.'
    response_headers = [('Content-Type', 'text/html'), ('Content-Length', str(len(content)))]
    start_response(status, response_headers)
    yield content.encode('utf8')

Hi, maybe it would be easier for you to use a framork, like Flask? Frameworks generally take care of some stuff making it easier to focus on the parts you actually care about mostly (meaning: what your app is supposed to do). We have a tutorial which might be inspiring for you: https://blog.pythonanywhere.com/169/.