Skip to content

tanrax/flask-note

master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
src
 
 
 
 
 
 
 
 

PyConES16: Flask-note (Clone of Evernote with Flask and Markdown)

DEMO

sketching/target.jpg

Install

Flask

mkdir flask-note
cd flask-note
pip install virtualenv
virtualenv ENV
source ENV/bin/activate
pip install Flask
pip install markdown

SQLite

OS X

brew install sqlite

Ubuntu

sudo apt-get update
sudo apt-get install sqlite3 libsqlite3-dev

Flask_sqlalchemy

pip install flask_sqlalchemy

Create Flask

Create app.py

from flask import Flask
from functools import wraps
app = Flask(__name__)

def login_required(f):
    @wraps(f)
    def decorated_function(*args, **kwargs):
        if 'user_id' not in session:
            session.clear()
            return redirect(url_for('index'))
        return f(*args, **kwargs)
    return decorated_function

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

if __name__ == "__main__":
    app.run()
python app.py

Open in your browser

http://127.0.0.1:5000/

Create Database

Create database.py

from flask import Flask
from flask_sqlalchemy import SQLAlchemy

app = Flask(__name__)
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///database.sqlite'
db = SQLAlchemy(app)


class User(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    email = db.Column(db.String(100), unique=True)
    password = db.Column(db.String(32))

    def __init__(self, email, password):
        self.email = email
        self.password = password

    def __repr__(self):
        return '<User {email}>'.format(email=self.email)


class Note(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    title = db.Column(db.String(100), unique=True)
    text = db.Column(db.Text())
    user_id = db.Column(db.Integer)

    def __init__(self, title, text, user_id):
        self.title = title
        self.text = text
        self.user_id = user_id

    def __repr__(self):
        return '<Note {title}>'.format(title=self.title)
python
from database import db
db.create_all()
exit()
sqlite3 database.sqlite
INSERT INTO user VALUES (NULL, 'py@con.es', '2016');
.exit

Future resource

master.html

<!doctype html>
<html lang="en">
  <head>
    <meta charset="UTF-8"/>
    <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0"/>
    <link href="https://bootswatch.com/flatly/bootstrap.min.css" rel="stylesheet">
    <title>Flask-note</title>
  </head>
  <body>
    <div class="container">
      <div class="page-header">
        <h1 class="text-center">
          <small>Flask-note</small>
        </h1>
      </div>
      <div class="row">
        {% block contain %}
        {% endblock %}
      </div>
    </div>
  </body>
</html>

About

PyConES16 workshop where Evernote is replicated through Flask

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published