Skip to content

Instantly share code, notes, and snippets.

@harit-sunrun
Created March 23, 2013 14:11
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save harit-sunrun/5227850 to your computer and use it in GitHub Desktop.
Save harit-sunrun/5227850 to your computer and use it in GitHub Desktop.
Registering multiple modules with flask blueprints. This will help to separate a project into multiple modules
# Project Structure
facebook/
runserver.py
feed/
__init__.py
views.py
chat/
__init__.py
views.py
# create blueprint in feed/__init__.py
from flask import Blueprint
feed = Blueprint('feed', __name__)
import views
# create blueprint in chat/__init__.py
from flask import Blueprint
chat = Blueprint('chat', __name__)
import views
# add views (endpoints) in feed/views.py
from . import feed
@feed.route('/feed')
def feed():
return 'feed'
# add views (endpoints) in chat/views.py
from . import chat
@chat.route('/chat')
def chat():
return 'chat'
# register blueprint and start flask app
from flask import Flask
from expense import expense
from budget import budget
app = Flask(__name__)
app.register_blueprint(feed)
app.register_blueprint(chat)
app.run(debug=True)
# In Action
* Running on http://127.0.0.1:5000/
# Hit Urls
http://127.0.0.1:5000/feed # output feed
http://127.0.0.1:5000/chat # output chat
@atupal
Copy link

atupal commented Sep 29, 2013

Is it:

from feed import feed
from chat import chat

but not

from expense import expense
from budget import budget

?

@vinaychittora
Copy link

Hey I am trying to run another app with Eve (https://github.com/nicolaiarocci/eve).
I cannot figure out how to get it done. Please help!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment