谷歌应用程序引擎(python):ImportError没有名为django的模块
因此,我尝试将 django 1.1 模板引擎与 Google App Engine Web 应用程序框架结合使用,来自此处。这是在 Ubuntu Jaunty 上,我已确保 PYTHONPATH 包含 Django-1.1.1 的位置,但当它尝试执行下面的 use_library() 行时,我收到此“ImportError:没有名为 django 的模块”错误。再说一次,有人可以帮助我吗?我很困惑。
import os
os.environ['DJANGO_SETTINGS_MODULE'] = 'settings'
from google.appengine.dist import use_library
use_library('django', '1.1')
So I'm trying to use the django 1.1 template engine with the google app engine web app framework, from here. This is on Ubuntu Jaunty, I've made sure that the PYTHONPATH contains the location of Django-1.1.1 yet I'm getting this 'ImportError: No module named django' error when it tries to execute the use_library() line below. Again, could somebody help me? I'm stumped.
import os
os.environ['DJANGO_SETTINGS_MODULE'] = 'settings'
from google.appengine.dist import use_library
use_library('django', '1.1')
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
想出了以下解决方案:
获取 django 1.1 并将其放在项目根目录下。
将空文件“non_gae_indicator”添加到项目根文件夹中。
将 django 和 non_gae_indicator 添加到您的 app.yamlskip_files 元素中:
现在我们有办法判断我们是在 GAE-sdk 下运行还是在实时运行 - 因为当我们实时运行时,non_gae_indicator 将不可用。
因此,在 main.py 中,您可以执行以下操作:
您应该使用 --allow_skipped_files 标志运行本地 SDK 服务器(否则在检查跳过的文件时,它们似乎不存在 - 服务器控制台会给出警告)。
Came up with the following solution:
Get django 1.1 and put it under your project root.
Add an empty file "non_gae_indicator" to your project root folder.
Add django and non_gae_indicator to your app.yaml skip_files element:
Now we have a way to tell whether we are running under the GAE-sdk or live - since non_gae_indicator won't be available when we are live.
So in main.py you can do:
You should run your local SDK server with the --allow_skipped_files flag (or else the skipped files will appear to not be exist when checking them - the server console gives a warning about it).
@stallarida - 问题是 .96 是默认随 SDK 一起提供的。我最后所做的是将 appengine 目录中的 django 版本更新为 1.1,这是一个肮脏的 hack,但有效。工作正常,需要在开发和生产之间进行一些调整。
具体来说,我必须在本地运行时注释掉
use_library('django', '1.1')
,但在上传我的应用程序时包含它。我确信有更好的解决方案,当我的 Linux 体验改善时我会解决它。
@stallarida - The problem is that .96 is shipped as default with the SDK. What I did in the end, which is a dirty hack but works, is to update the version of django in the appengine directory to 1.1. Worked fine, needed a bit of tweaking between dev and production.
Specifically I had to comment out
use_library('django', '1.1')
when running locally but include it when uploading my app.I'm sure there's a better solution and I'll work it out when my linux experience improves.