ImportError:在Google应用引擎中找不到django.utils

时间:2021-04-13 23:13:57

I get this error when I use simplejson from django.utils in google app engine project:

当我在谷歌应用引擎项目中使用来自django.utils的simplejson时,我收到此错误:

Traceback (most recent call last):
  File "/base/python27_runtime/python27_lib/versions/1/google/appengine/runtime/wsgi.py", line 187, in Handle
    handler = _config_handle.add_wsgi_middleware(self._LoadHandler())
  File "/base/python27_runtime/python27_lib/versions/1/google/appengine/runtime/wsgi.py", line 225, in _LoadHandler
    handler = __import__(path[0])
  File "/base/data/home/apps/s~testapp/1.359839747994604729/notify.py", line 8, in <module>
    from handlers.xmpp_handler import XMPPHandler
  File "/base/data/home/apps/s~testapp/1.359839747994604729/handlers/xmpp_handler.py", line 12, in <module>
    import commands
  File "/base/data/home/apps/s~testapp/1.359839747994604729/handlers/commands.py", line 4, in <module>
    from django.utils import simplejson
ImportError: No module named django.utils

Snippet:

import datetime
from google.appengine.api import users
from google.appengine.ext import db
from django.utils import simplejson

class jsonEncoder(simplejson.JSONEncoder):
    def default(self, obj):
        if isinstance(obj, datetime.datetime):
            return obj.isoformat()

        elif isinstance(obj, db.Model):
            return dict((p, getattr(obj, p)) 
                        for p in obj.properties())

        elif isinstance(obj, users.User):
            return obj.email()

        else:
            return simplejson.JSONEncoder.default(self, obj)

1 个解决方案

#1


15  

You need to specify that you want to use django in your app.yaml:

您需要在app.yaml中指定要使用django:

libraries:
- name: django
  version: "1.2"

See the GAE docs for the supported django versions.

有关支持的django版本,请参阅GAE文档。

On Python 2.7 runtime, you should be using python's native json library instead of simplejson though.

在Python 2.7运行时,您应该使用python的本机json库而不是simplejson。

#1


15  

You need to specify that you want to use django in your app.yaml:

您需要在app.yaml中指定要使用django:

libraries:
- name: django
  version: "1.2"

See the GAE docs for the supported django versions.

有关支持的django版本,请参阅GAE文档。

On Python 2.7 runtime, you should be using python's native json library instead of simplejson though.

在Python 2.7运行时,您应该使用python的本机json库而不是simplejson。