Giter Site home page Giter Site logo

flasktodo's Introduction

Flask is a micro framework for python. I wanted to create a simple example using Flask on Google App Engine so I created this todo list app.

You can try it out for yourself at flasktodo.appspot.com. To give you an idea of how simple coding in a micro framework can be I’ve included the code below.

application.py

from flask import Flask
app = Flask(__name__)

from google.appengine.ext import db
from google.appengine.api import users

from flask import redirect, url_for, request, render_template, abort, flash, get_flashed_messages

class Task(db.Model): 
    user = db.UserProperty()
    name = db.StringProperty(required=True)
    done = db.BooleanProperty()

@app.route('/')
def list():
    user = users.get_current_user()
    tasks = Task.all().filter('user =', user)
    return render_template('list.html', user=user, logout_url=users.create_logout_url("/"), tasks=tasks, flashes=get_flashed_messages());

@app.route('/', methods=['POST'])
def task_post():
    name = request.form['name']
    if not name:
        flash("Oops you forgot to set a task name.")
        return redirect(url_for('list'))
    task = Task(name = request.form['name'])
    task.user = users.get_current_user()
    task.put()
    return redirect(url_for('list'))

@app.route('/delete/<int:id>')
def task_delete(id):
    task = Task.get_by_id(id)
    if task and task.user == users.get_current_user():
        task.delete()
    else:
        abort(404)

    return redirect(url_for('list'))

@app.route('/done/<int:id>')
def task_done(id):
    task = Task.get_by_id(id)
    if task and task.user == users.get_current_user():
        if task.done:
            task.done = False
        else: 
            task.done = True
        task.put()
    else:
        abort(404)

    return redirect(url_for('list'))


# set the secret key.  keep this really secret:
app.secret_key = 'the secret key'

if __name__ == '__main__':
    app.run()

flasktodo's People

Contributors

gigq avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.