Commits

Brent Tubbs  committed c16eb39

initial commit

  • Participants

Comments (0)

Files changed (5)

+syntax: glob
+*.pyc
+.*.swp
+.*.swo
+*~
+*.orig
+*.idea
+*.egg
+._*
+.DS_Store
+pip-log.txt
+build/*
+dist/*
+tmp/*
+run/*
+_build/*
+This repo was created to answer a question on the flask mailing list regarding
+Flask/MongoEngine integration.  See http://flask.pocoo.org/mailinglist/archive/2011/6/9/database-in-large-application/
+
+This is a trivial app showing how to use mongoengine with flask.  The page
+shows and records pageviews in mongoDB, using a MongoEngine model.
+
+import mongoengine as mgo
+
+class Counter(mgo.Document):
+    hits = mgo.IntField(default=0)
+
+    meta = {
+        'allow_inheritance': False
+    }
+
+

File models.pyc

Binary file added.
+import mongoengine as mgo
+from models import Counter
+from flask import Flask
+
+app = Flask(__name__)
+
+@app.route('/')
+def counter():
+    if Counter.objects.count() == 0:
+        c = Counter()
+    else:
+        c = Counter.objects.first()
+
+    hits = c.hits
+    c.hits += 1
+    c.save()
+    return "I have been viewed %s times." % hits
+
+
+if __name__ == '__main__':
+    mgo.connect('flask_test')
+    app.run()