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 Flask Basics Welcome to Flask View Args Through URL

I'm just not getting the language

This looked correct to me. I have add the ' after / = '/' That did not work not sure what syntx error there is?

flask_app.py
from flask import Flask

app = Flask(__name__)


@app.route('/')
def hello():
     return 'Hello Student'

@app.route('/<name>')
def hello():

1 Answer

Ari Misha
Ari Misha
19,323 Points

Hiya Kaleb! Do you know anything about MVC architecture? If you dont , be sure to research a bit about it and then come back to read this comment. In Django or Flask or Pyramid (web development framework written python) follows something similar to MVC architecture. Instead of calling it MVC , Python community call it Model-View-Templates. And View serves as your controller in Flask and it also has routes defined.

Now your "flask_app.py" serves as a "View". This file links your model to routes and vice versa. Kinda like vice versa. "@app.route" is decorator which takes an argument , which is a.....well route or path(relative path). So when a request comes in for "index" page of your application, its going to pass the request to "index" function , and whatever you've coded in "index" function , its going to send it to the "Template" and render in the browser. Exactly like how your index function is going to render "Hello Student".

Now regarding your challenge, here is the code for reference:

from flask import Flask

app = Flask(__name__)


@app.route('/')
@app.route('/<name>')
def hello(name):
     return 'Hello Student'