Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python

Display python on browser

Hi all, just started to learn Python. However I’m totally unwise to how you link you python code to html.file just as you would with Javascript.

With Javascript and html you need only to create a html and is.file. Does the same apply with python and if so what is the code please?

2 Answers

Jeff Muday
MOD
Jeff Muday
Treehouse Moderator 28,732 Points

Python is quite unlike JavaScript or PHP programming that is primarly client side. A Python script is often run as an independent program on a server that answers/responds/renders requests as a worker behind Nginx or Apache, or possibly as a CGI or Fast-CGI script depending on your deployment scenario.

If you understand JavaScript, it is not too hard to jump right in an begin investigating simple Python micro frameworks. Treehouse has some excellent material associated with learning the Flask framework. Treehouse has all the tools you need to edit and deploy scripts-- you don't need a hosting account or fancy IDE to get going.

Most frameworks include a development server that is easily activated and serves pages that can be rendered in a browser.

Below, is a skeletal program for Flask framework that returns a simple Hello World message when a browser is directed to the host and port 8080.

Once you get some Flask under your belt, you can learn about how your Python script can be run as a worker behind Nginx or Apache.

from flask import Flask
app = Flask(__name__)

@app.route('/')
def index():
    return "Hello World"

app.run(host='0.0.0.0', port=8080)

That’s I will check it out