This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
john = { | |
'name' : 'John', | |
'hair' : 'brown', | |
'from' : 'PA', | |
'limbs' : 4, | |
'colors' : ['green','brown','orange'] | |
} | |
fed = { | |
'name' : 'Federico', |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Astronaut(object): | |
# properties/atrributes/variables describe the object | |
# __init__ automatically called when creating an object | |
def __init__(self, nameStr = None): | |
print "Creating new astronaut:", nameStr | |
self.name = nameStr | |
# VERB sets a attribute | |
def set_name(self, nameStr): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Configuration | |
app.configure(function(){ | |
app.set('views', __dirname + '/views'); | |
app.set('view engine', 'ejs'); | |
app.set('view options',{layout:true}); // use /views/layout.html to manage your main header/footer wrapping template | |
app.register('html',require('ejs')); //use .html files in /views instead .hbs | |
app.use(express.cookieParser()); | |
app.use(express.bodyParser()); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
from mongoengine import * | |
from flask.ext.mongoengine.wtf import model_form | |
from datetime import datetime | |
class Comment(EmbeddedDocument): | |
name = StringField() | |
comment = StringField() | |
timestamp = DateTimeField(default=datetime.now()) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# this is our main page | |
@app.route("/", methods=['GET','POST']) | |
def index(): | |
# get Idea form from models.py | |
idea_form = models.IdeaForm(request.form) | |
# if form was submitted and it is valid... | |
if request.method == "POST" and idea_form.validate(): | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<form method="POST" role="form"> | |
{{ form.csrf_token }} | |
<legend><h3>Share Your Ideas</h3></legend> | |
{% if form.errors %} | |
<ul class="errors"> | |
{% for field_name, field_errors in form.errors|dictsort if field_errors %} | |
{% for error in field_errors %} | |
<li>{{ form[field_name].label }}: {{ error }}</li> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# put this in your app.py | |
@app.route("/nuts") | |
def nutbutter(): | |
# nuts and review | |
nuttbutterReviews = { | |
'almond' : 'great', | |
'peanut' : 'okay', | |
'walnut' : 'what is this stuff?' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# If /json route receives header "application/json" | |
@app.route("/json", methods=['GET','POST']) | |
def json(): | |
app.logger.debug("JSON received...") | |
app.logger.debug(request.json) | |
if request.json: | |
mydata = request.json # will be |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{% extends "layout/main.html" %} | |
{% block body %} | |
<div class="row"> | |
<div class="span6"> | |
<form method="POST"> | |
<label for="date">Pick a date</label> | |
<input type="date" name="date" id="date"> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
from mongoengine import * | |
from flask.ext.mongoengine.wtf import model_form | |
from datetime import datetime | |
class Comment(EmbeddedDocument): | |
name = StringField(required=False) | |
comment = StringField() |