gpt4 book ai didi

django - 在 Google 应用引擎中找不到 ImportError : django. 实用程序

转载 作者:太空宇宙 更新时间:2023-11-03 15:26:30 24 4
gpt4 key购买 nike

当我在 google app engine 项目中使用来自 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

片段:

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)

最佳答案

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

libraries:
- name: django
version: "1.2"

参见 GAE docs对于支持的 django 版本。

在 Python 2.7 运行时,你应该使用 python 的 native json library而不是 simplejson。

关于django - 在 Google 应用引擎中找不到 ImportError : django. 实用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11174750/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com