Skip to content

Instantly share code, notes, and snippets.

@jsutch
Created May 17, 2016 00:29
Show Gist options
  • Save jsutch/7ff2f57bead4c518d41865f37f474357 to your computer and use it in GitHub Desktop.
Save jsutch/7ff2f57bead4c518d41865f37f474357 to your computer and use it in GitHub Desktop.
New Test
# Assignment: Landing Page
# MandatoryDeadline: Monday of Week 4Difficulty Level: BasicEstimated Time: 1-2 hrs
# Create a flask project capable of handling the following routes:
# localhost:5000/ This route should serve a view file called index.html and display a greeting.
# localhost:5000/ninjas This route should serve a view file called ninjas.html and display information about ninjas.
# localhost:5000/dojos/new This route should serve a view file called dojos.html and have a form (don't worry where the form should be sent to - action=' ').
# Now create a folder inside of our project labeled static. Remember, this static folder will be used to serve all of our static content (stylesheets, images, javascript files, etc.)! Now try placing a stylesheet in the static folder and referencing it in our view files (templates).
from flask import Flask, render_template, url_for
app = Flask(__name__)
@app.route('/')
def index():
return render_template("index2.html", phrase="Hello", times=5, name="Bob")
@app.route('/ninjas')
def test():
return render_template("ninjas.html", phrase="Hello", times=5, name="Bob")
@app.route('/dojos/new')
def dojos():
return render_template("dojos.html", phrase="Hello", times=5, name="Bob")
@app.route('/users', methods=['POST'])
def create_user():
print "Got Post Info"
# we'll talk about the following two lines after we learn a little more
# about forms
name = request.form['name']
email = request.form['email']
# redirects back to the '/' route
return redirect('/')
app.run(debug=True)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment