1

これが私がこれまでに行ったことです。

1) Django をインストールし、以下を使用してプロジェクトを開始しました。

django-admin.py startproject helloworld

2)django non-rel、djangotoolbox、およびdjango-mongodb-engineをダウンロードし、これらを使用してインストールしました sudo python setup.py install

3) INSTALLED_APPS に djangotoolbox を追加し、データベース バックエンド エンジンとして django_mongodb_engine を追加しました。

4) 次のようなサンプル モデルがあります。

from django.db import models
from djangotoolbox import *

class Post(models.Model):
    title = models.CharField()
    text = models.TextField()
    tags = ListField()
    comments = ListField()

5)次を使用してpython replを開始しました:python manage.py shell

6)そしてこれをしました:

    from hello.models import Post
    post = Post.objects.create(
...     title='Hello MongoDB!',
...     text='Just wanted to drop a note from Django. Cya!',
...     tags=['mongodb', 'django']
... )

このエラーが発生しました。これを修正する方法がわかりません

Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "/usr/local/lib/python2.6/dist-packages/django/db/models/manager.py", line 149, in create
    return self.get_query_set().create(**kwargs)
  File "/usr/local/lib/python2.6/dist-packages/django/db/models/query.py", line 416, in create
    obj.save(force_insert=True, using=self.db)
  File "/usr/local/lib/python2.6/dist-packages/django/db/models/base.py", line 546, in save
    force_update=force_update, update_fields=update_fields)
  File "/usr/local/lib/python2.6/dist-packages/django/db/models/base.py", line 650, in save_base
    result = manager._insert([self], fields=fields, return_id=update_pk, using=using, raw=raw)
  File "/usr/local/lib/python2.6/dist-packages/django/db/models/manager.py", line 215, in _insert
    return insert_query(self.model, objs, fields, **kwargs)
  File "/usr/local/lib/python2.6/dist-packages/django/db/models/query.py", line 1675, in insert_query
    return query.get_compiler(using=using).execute_sql(return_id)
  File "/usr/local/lib/python2.6/dist-packages/django/db/models/sql/query.py", line 237, in get_compiler
    return connection.ops.compiler(self.compiler)(self, connection, using)
  File "/usr/local/lib/python2.6/dist-packages/django/db/backends/__init__.py", line 703, in compiler
    self._cache = import_module(self.compiler_module)
  File "/usr/local/lib/python2.6/dist-packages/django/utils/importlib.py", line 35, in import_module
    __import__(name)
  File "/home/home/Desktop/helloworld/django_mongodb_engine/compiler.py", line 18, in <module>
    from djangotoolbox.db.basecompiler import (
  File "/usr/local/lib/python2.6/dist-packages/djangotoolbox-1.4.0-py2.6.egg/djangotoolbox/db/basecompiler.py", line 9, in <module>
    from django.db.models.sql.constants import LOOKUP_SEP, MULTI, SINGLE
ImportError: cannot import name LOOKUP_SEP

ここで何が間違っていますか?どうすれば修正できますか?

4

1 に答える 1

0

LOOKUP_SEPDjango 1.4 ではここにありましたが、1.5 では削除されたので、古いバージョンの djangotoolbox を使用していると思います。

おそらくパッケージを更新する必要があります。次の手順に従ってください: http://django-mongodb-engine.readthedocs.org/en/latest/topics/setup.html

于 2013-12-25T22:22:27.873 に答える