Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error in Tumblelog Application development using Flask and MongoEngine

I am trying to follow below tutorial but I am facing few issue, when i run manage.py. Any help could be great help.

http://docs.mongodb.org/ecosystem/tutorial/write-a-tumblelog-application-with-flask-mongoengine/#id1

manage.py run output:

 (Tumbler)afiz Tumbler $ python manage.py 
Traceback (most recent call last):
  File "manage.py", line 6, in <module>
    from tumblelog import app
  File "/home/afiz/.virtualenvs/tumblelog/__init__.py", line 18, in <module>
    register_blueprints(app)
  File "/home/afiz/.virtualenvs/tumblelog/__init__.py", line 13, in register_blueprints
    from tumblelog.views import posts
  File "/home/afiz/.virtualenvs/tumblelog/views.py", line 5, in <module>
    from tumblelog.models import Post, Comment
  File "/home/afiz/.virtualenvs/tumblelog/models.py", line 6, in <module>
    class Post(db.DynamicDocument):
  File "/home/afiz/.virtualenvs/Tumbler/local/lib/python2.7/site-packages/mongoengine/base/metaclasses.py", line 361, in __new__
    meta['index_specs'] = new_class._build_index_specs(meta['indexes'])
  File "/home/afiz/.virtualenvs/Tumbler/local/lib/python2.7/site-packages/mongoengine/base/document.py", line 722, in _build_index_specs
    unique_indices = cls._unique_with_indexes()
  File "/home/afiz/.virtualenvs/Tumbler/local/lib/python2.7/site-packages/mongoengine/base/document.py", line 861, in _unique_with_indexes
    field.document_type != cls):
  File "/home/afiz/.virtualenvs/Tumbler/local/lib/python2.7/site-packages/mongoengine/fields.py", line 563, in document_type
    self.document_type_obj = get_document(self.document_type_obj)
  File "/home/afiz/.virtualenvs/Tumbler/local/lib/python2.7/site-packages/mongoengine/base/common.py", line 25, in get_document
    """.strip() % name)
mongoengine.errors.NotRegistered: `Comment` has not been registered in the document registry.
            Importing the document class automatically registers it, has it
            been imported?

manage.py file:

    #set the path
import os, sys
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))

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

manager = Manager(app)

# Turn on debugger by default and reloader
manager.add_command("runserver", Server(
    use_debugger = True,
    use_reloader = True,
    host = '0.0.0.0')
)

if __name__ == "__main__":
    manager.run()
like image 481
Afiz Avatar asked Apr 03 '15 15:04

Afiz


2 Answers

I had the same problem as you are facing now. In models.py file I just wrote

class Comment(db.EmbeddedDocument):

and it's content first then added

class Post(db.Document):

and then it's content. In other words, I first wrote Comment class then Post class and problem got solved ;) :) Cheers!!

like image 162
stillfool Avatar answered Oct 19 '22 02:10

stillfool


Inside Post, when EmbeddedDocumentField is assigned to a variable, it needs to be pre-registered. Therefore, always register such field i.e. Comments before they are used.

like image 1
ebd Avatar answered Oct 19 '22 04:10

ebd