2015-04-03 11 views
11

Sto cercando di seguire il tutorial qui sotto, ma sto affrontando qualche problema, quando eseguo manage.py. Qualsiasi aiuto potrebbe essere di grande aiuto.Errore nello sviluppo di applicazioni Tumblelog usando Flask e MongoEngine

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

manage.py uscita run:

(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? 

file di manage.py:

#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() 
+0

Che aspetto hanno i tuoi modelli? – dirn

+0

Uscita congelamento PIP: (Tumbler)afiz .virtualenvs $ pip freeze Flask==0.10.1 Flask-Script==2.0.5 Flask-WTF==0.8.4 Jinja2==2.7.3 MarkupSafe==0.23 WTForms==2.0.2 Werkzeug==0.10.4 argparse==1.2.1 flask-mongoengine==0.7.1 itsdangerous==0.24 mongoengine==0.9.0 pymongo==2.8 wsgiref==0.1.2 (Tumbler)afiz .virtualenvs $ cd Tumbler/ (Tumbler)afiz Tumbler $ ls bin include __init__.py lib local manage.py requirements.txt (Tumbler)afiz Tumbler $ Afiz

+0

la risposta di @ stillfool ha funzionato per me. Come stai? Probabilmente dovresti accettarlo, agganciare un amigo con alcuni punti. –

risposta

18

Ho avuto lo stesso problema, come si sta affrontando ora. Nel file di models.py ho appena scritto

classe Comment (db.EmbeddedDocument):

e il suo contenuto prima poi aggiunto

classe Post (db.Document):

e quindi è contenuto. In altre parole, ho scritto per la prima volta il commento di classe e poi post di classe e il problema è stato risolto;) :) Saluti !!

+1

Se si definisce 'Post' prima di' Comment', è necessario assicurarsi di passare il nome come stringa (ad esempio, '' Comment''). – dirn

+1

wow, non posso credere che questo ha funzionato. Questa dovrebbe essere la risposta accettata. –

1

Inside Post, quando EmbeddedDocumentField è assegnato a una variabile, deve essere pre-registrato. Pertanto, registra sempre tale campo, ad esempio i commenti prima che vengano utilizzati.

Problemi correlati