Skip to content

Updates to the flask mongoengine tutorial #58

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 10, 2012
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -84,15 +84,15 @@ Install with the following commands:
pip install flask
pip install flask-script
pip install WTForms
pip install https://github.com/hmarr/mongoengine/tarball/dev
pip install https://github.com/rozza/flask-mongoengine/tarball/master
pip install mongoengine
pip install flask_mongoengine

Continue with the tutorial to begin building the "tumblelog"
application.

.. _WTForms: http://wtforms.simplecodes.com/docs/dev/
.. _Flask-Script: http://pypi.python.org/pypi/Flask-Script
.. _Flask-MongoEngine: http://github.com/rozza/flask-mongoengine
.. _Flask-MongoEngine: http://github.com/MongoEngine/flask-mongoengine

Build a Blog to Get Started
---------------------------
Expand Down Expand Up @@ -120,7 +120,7 @@ provides a development server and shell:
import os, sys
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))

from flaskext.script import Manager, Server
from flask.ext.script import Manager, Server
from tumblelog import app

manager = Manager(app)
Expand Down Expand Up @@ -157,10 +157,11 @@ Install the Flask_ extension and add the configuration. Update
.. code-block:: python

from flask import Flask
from flaskext.mongoengine import MongoEngine
from flask.ext.mongoengine import MongoEngine

app = Flask(__name__)
app.config["MONGODB_DB"] = "my_tumble_log"
app.config["SECRET_KEY"] = "KeepThisS3cr3t"

db = MongoEngine(app)

Expand Down Expand Up @@ -203,6 +204,7 @@ In this application, you will define posts and comments, so that each
return self.title

meta = {
'allow_inheritance': True,
'indexes': ['-created_at', 'slug'],
'ordering': ['-created_at']
}
Expand Down Expand Up @@ -442,7 +444,7 @@ and the :py:class:`DetailView` class to this file:

.. code-block:: python

from flaskext.mongoengine.wtf import model_form
from flask.ext.mongoengine.wtf import model_form

...

Expand Down Expand Up @@ -501,7 +503,7 @@ create comments. Create a macro for the forms in
{% macro render(form) -%}
<fieldset>
{% for field in form %}
{% if field.type == 'HiddenField' %}
{% if field.type in ['CSRFTokenField', 'HiddenField'] %}
{{ field() }}
{% else %}
<div class="clearfix {% if field.errors %}error{% endif %}">
Expand Down Expand Up @@ -619,7 +621,7 @@ following view is deliberately generic, to facilitate customization.
from flask import Blueprint, request, redirect, render_template, url_for
from flask.views import MethodView

from flaskext.mongoengine.wtf import model_form
from flask.ext.mongoengine.wtf import model_form

from tumblelog.auth import requires_auth
from tumblelog.models import Post, Comment
Expand Down Expand Up @@ -831,6 +833,7 @@ class and create new classes for the new post types. Update the
return self.__class__.__name__

meta = {
'allow_inheritance': True,
'indexes': ['-created_at', 'slug'],
'ordering': ['-created_at']
}
Expand Down