• Stars
    star
    135
  • Rank 267,805 (Top 6 %)
  • Language
    Python
  • Created almost 11 years ago
  • Updated over 4 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Flask, Flask-Login & MongoDB example

Flask Login Demo

Demo: http://itppylogindemo.herokuapp.com/

Flask Login

This code sample makes use of Flask and Flask-Login, a library that manages User registration, log in, session and logout functionality.

Flask-Login Documentation

Demo App ..

  • register and login users.
  • create notes saved in database and associated to a specific user.
  • users can edit their own notes.

To get started

  • Download code

  • Create Git repo

      git init
      git add .
      git commit -am "init commit"
    
  • Create a virtual environment

      virtualenv venv
    
  • Install all requirements for app

      . runpip
    

    or

      . venv/bin/activate
      pip install -r requirements.txt
    
  • Create Heroku app

      heroku create
    
  • Add MongoLab Starter Addon to your app, from your code directory in Terminal

      heroku addons:add mongolab
    
  • Add MONGOLAB_URI from Heroku config to your .env file

      heroku config --shell | grep MONGOLAB_URI >> .env
    

Create a SECRET_KEY for your .env and Heroku Config

We need a SECRET_KEY for salting the user passwords.

  • Open your .env and add a new line

      SECRET_KEY=SOMETHINGSECRETANDRANDOMHERE
      DEBUG=True
    
  • We need to add this secret key to Heroku config vars too

      heroku config:add SECRET_KEY=SOMETHINGSECRETANDRANDOMHERE
    

This will add a new key and value to the App on Heroku.

Run it

With your MONGOLAB_URI and SECRET_KEY configured in .env and on Heroku config you should be good to run the code.

Run,

. start

or

. venv/bin/activate
foreman start

The routes

  • / - main page - display all notes.
  • /notes/:note_id - display an individual note
  • /notes/:note_id/edit - display edit page for note, only user that created the note can edit.
  • /register - create a new user
  • /login - login with registered email and password
  • /logout - logout user

Flask Blueprints - Modular Flask Development

Flask Blueprint docs

Blueprints allow you to separate your app into modules removing core code from App.py and making the Blueprints little apps that get registered and work together in one large application.

Running the server

run_server.py

foreman start

If you don't have foreman, download and install the Heroku Toolbelt

run_server.py does the following tasks to get the app ready

  • Imports app.py - app.py implements database connection, session management, login manager setup.
  • Imports blueprints
    • notes.py - routes for all note display, create and edit
    • auth.py - routes for login, registration and logout

More Repositories

1

node-session

Code Samples from ITP Camp session
JavaScript
24
star
2

NodeJS-with-ExpressJS-and-MongoDB

example of using mongodb with ExpressJS
JavaScript
22
star
3

Instagram---Python-Flask-example

Python
19
star
4

Heroku-Boilerplate

Bare bones files for a NodeJS app on Heroku
JavaScript
13
star
5

UnoJoy-w-BT-SoftwareSerial

UnoJoy arduino uno with sparkfun bluetooth & software serial
Arduino
12
star
6

itp-dwd-flask-s3-upload

Flask example of uploading file to s3 w/ Boto
CSS
8
star
7

DWD-NodeJS-Passport-Demo

Example using Passport Local Mongo on Heroku
CSS
7
star
8

Python-Twitter-Flask-Example

example app to query and post to Twitter
Python
7
star
9

DWD-Sample-Readme

a sample README
6
star
10

python-websocket-serial

Simple Tkinter gui to control websocket to serial (and vice versa) communication
Python
5
star
11

DWD-User-Authentication

User auth example with NodeJS, Express, Passport and Mongo
JavaScript
5
star
12

dwd-nodejs-remote-apis

JavaScript
5
star
13

Heroku-ExpressJS-Boilerplate

JavaScript
4
star
14

ExpressJs-Valentine-Card-Maker

JavaScript
4
star
15

PS3-Interface

Control PS3 from your computer, designed as assistive technology but could have other uses as well.
Java
3
star
16

DWD-Flask-User-Demo

Demo site of Flask User Authentication and Management
JavaScript
3
star
17

Ramps-Processing-Sketch

Java
2
star
18

DWD-Blog-with-User-Authentication

JavaScript
2
star
19

ExpressJS-with-Hunch-API-example

JavaScript
2
star
20

Processing-XML-Buttons

Sample code to read an xml file and display the associated buttons. On mouse drag, XML file is updated.
Java
2
star
21

DWD-Processing

Sample Processing Sketch using JSON data from ExpressJS app
JavaScript
2
star
22

itpjsweek_nodejs

Getting started with NodeJS examples for ITP's JavaScript Week
JavaScript
2
star
23

itppy-dwd-realtime

Demo Flask with AJAX + Flask with Pusher
CSS
2
star
24

DWD-Google-Maps-Sample

JavaScript
1
star
25

ITP-DWD-Python-Class

Class website built in Flask pushed to Heroku
JavaScript
1
star
26

DWD-Relay

example of using Socket.io on Heroku with NodeJS and ExpressJS
JavaScript
1
star
27

DWD-NodeJS-S3-Demo

JavaScript
1
star
28

DoodleThing

JavaScript
1
star
29

Cably

JavaScript
1
star
30

Appengine-itpcamp-session

ITP Camp AppEngine session
1
star
31

itp-py-dwd-remote-apis

ITP DWD Fall 2012 - Using remote web apis demo
Python
1
star
32

ITP-DWD-Fall2013-Week3-First-Server

Full Flask, Virtualenv web server example that is ready for Heroku
Python
1
star
33

Video-tracking-mouse-control

Processing + Java Robot for mouse movement
Java
1
star
34

DynamicWebClass

JavaScript
1
star
35

Ramps---Arduino-code

Ramps - wheelchair dj project - arduino code for 2 rotary encoders to Processing
Arduino
1
star
36

BerlinBicycle

Berlin bicycle mapping project for the BMW Guggenheim Lab
JavaScript
1
star
37

ITPediatrics-ebook-jquery-mobile

1
star
38

Single-Switch-with-Processing

Java
1
star
39

motion-flexion

simple arduino potentiometer reading to processing sketch to display graph and log
1
star