-
Setup your initial route at
/to return'Hello World'.Example: A GET request to
localhost:5000/would return'Hello World'. -
Build a route called
/birthdaythat returns your birthday as astringin this format:'October 30 1911'.Example: A GET request to
localhost:5000/birthdayreturns'October 30 1911'(Use your birthday instead) -
Build a route called
/greetingthat accepts a parameter calledname. The route should return a string that says'Hello <name>'where<name>is the name that you passed to the route.Example: A GET request to
localhost:5000/greeting/benwould return 'Hello ben!' -
Modify your home route (
/) to return the html template provided below.- Create a folder called
templatesin the root of your project's directory. - Create a file called
home.htmlin the templates directory. - Paste the HTML shown below into
home.htmland save. - In your main server file modify the
flaskimport line to say:from flask import Flask, render_template - In your home (
/) routereturn render_template('home.html'). - Navigate to
localhost:5000/and you should see the rendered HTML.
- Create a folder called
Your file structure should look like this:
project-name/
--server.py (or whatever you named your python script)
--templates/
---- home.html
--venv/
Paste this HTML into home.html.
<!DOCTYPE html>
<html>
<body>
<img src="https://lambdaschool.com/static/assets/images/lambda.png">
<h1>Congrats!</h1>
<h3>You just served your first webpage.</h3>
<p>This page is pretty bare right now but these are the fundamentals that all websites are built on. Later in the course we will teach you some basic HTML, CSS, and Javascript so that you can structure more sophisticated pages with more detailed designs and complex functionality</p>
<p>Our full time and part time courses will go much more in depth as to what it takes to build the same kinds of web applications that you know and love. We will be covering the cutting edge frameworks used by industry leaders to create highly performant and beautiful applications.</p>
</body>
</html>
-
Create a route called
/addthat adds two parameteres together and returns them.localhost:5000/add/5/10would return'15'- You will need to convert the parameters to integers using
int() - Example:
fiveAsInt = int('5')=>fiveAsInt == 5 - You then have to convert the
intback into astringusingstr() - Example:
fiveAsString = str(5)=>fiveAsString == '5' - You can also prefix the parameter with the keyword
int=><int:param>. Make sure you turn it back into astring
-
Create a route called
/multiplyand a route called/subtractlocalhost:5000/multiply/6/5would return'30'localhost:5000/subtract/25/5would return'20'- Make sure you are converting the parameters to
ints and returning astring
-
Create a route called
/favoritefoodsthat returns alistof your favorite foods- A
listis a collection of different values. =>['football', 'basketball', 'rugby'] - The server must return a string so we need to convert our list into a string.
- One common string format for sending complex data is
JSON. - Change the top line of your server file to
from flask import Flask, render_template, jsonify - Pass your
listtojsonify()when returning it.return jsonify(myList)
- A
Apply to our full time or part time immersive program to learn cutting edge technologies that are used by top technology companies around the world.
Our part time and full time courses are 13 intense weeks of focused study on the most relevant technologies.
Class sizes are small to ensure that each student gets individual attention from our world class instructors to help them succeed.
For more information visit: https://lambdaschool.com