Tumblelog Application with Flask and MongoEngine example does not work - Complete Novice

flask, mongodb, python

Solution

`register_blueprints` is never called - `app.run` blocks until you kill the script (at which point there is no point to adding routes).

Change the order and everything will run:

def register_blueprints(app):
# Prevents circular imports
    from tumblelog.views import posts
    app.register_blueprint(posts)

register_blueprints(app)

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

`regist_blueprints` is not actually preventing circular imports - the pattern to avoid circular imports is to create the `app` in a different file and import both `app` and `blueprint` into a third file to run everything:

#  application.py
from flask import Flask  # etc.

app = Flask("your_package_name")
# tumblelog/views.py
from flask import Blueprint, current_app  # etc.

posts = Blueprint("tumblelog")

@posts.route("/")
def index():
    # use current_app rather than app here
# run_server.py (use the same pattern for .wsgi files)
from application import app
from tumblelog.views import posts

app.register_blueprint(posts)

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

Problem

The Tumblelog app on the MongoDB site does not work . I've followed the example absolutely and I get a 404 error when I run it in my local host. I'm using Eclipse Indigo (3.7.2) with pyDev on Ubuntu 12.0.4. I'm not sure if it's because of the `register_blueprints`, which I included in the `__init__.py` I did it like this as in the tutorial: ``` from flask import Flask from flask.ext.mongoengine import MongoEngine app = Flask(__name__) app.config["MONGODB_DB"] = "my_tumble_log" app.config["SECRET_KEY"] = "KeepThisS3cr3t" db = MongoEngine(app) if __name__ == '__main__': app.run() def register_blueprints(app): # Prevents circular imports from tumblelog.views import posts app.register_blueprint(posts) register_blueprints(app) ``` Otherwise I have followed the tutorial exactly.

Original source