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

it doesn't work I put in a file named templates it can find the file but it still doesn't work? thanks

add.html

<!doctype html>
<html>
<head>
<title> hello world </title>
<body>
<h1>{{ num1 }}+{{ num2 }} = {{num1 + num2}} </h1>

</body>
</html>

heres is shoplist.py

from flask import Flask
from flask import render_template

app = Flask(__name__)


@app.route('/')
@app.route('/<name>')
def index(name="rodney"):
    return "hello from {}".format(name)



@app.route('/add/<int:num1>/<int:num2>')
@app.route('/add/<float:num1>/<float:num2>')
@app.route('/add/<int:num1>/<float:num2>')
@app.route('/add/<float:num1>/<int:num2>')
def add(num1,num2):
    context = {'num1':num1, 'num2':num2}
    return render_template("add.html",**context)


app.run(debug=True,port=7000,host="0.0.0.0")

excuse the indentation I got that part right

[MOD: added ```python formatting -cf]

Chris Freeman
Chris Freeman
Treehouse Moderator 68,423 Points

Verifying you have files set up as:

./shoplist.py
./templates/add.html

Can you explain what isn't working? What are you trying and what is the result?

1 Answer

From the Flask Docs' Quickstart:

Flask will look for templates in the templates folder. So if your application is a module, this folder is next to that module, if it’s a package it’s actually inside your package:

Case 1: a module:

/application.py
/templates
    /hello.html

Case 2: a package:

/application
    /__init__.py
    /templates
        /hello.html