0

我正在尝试使用 GAE、Django 构建一个 Web 应用程序。用户注册将是 userena。我已经使用 django-nonrel 和所有设置来使第一部分正常工作,我正在尝试为 userena 同步数据库。我不断收到这个错误,你能帮我解决这个问题吗?

BB8265:epapyri-django$ sudo django-admin.py syncdb
Password:
Traceback (most recent call last):
  File "/usr/local/bin/django-admin.py", line 5, in <module>
    management.execute_from_command_line()
  File "/Library/Python/2.7/site-packages/django/core/management/__init__.py", line 443, in execute_from_command_line
    utility.execute()
  File "/Library/Python/2.7/site-packages/django/core/management/__init__.py", line 382, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/Library/Python/2.7/site-packages/django/core/management/__init__.py", line 261, in fetch_command
    klass = load_command_class(app_name, subcommand)
  File "/Library/Python/2.7/site-packages/django/core/management/__init__.py", line 69, in load_command_class
    module = import_module('%s.management.commands.%s' % (app_name, name))
  File "/Library/Python/2.7/site-packages/django/utils/importlib.py", line 35, in import_module
    __import__(name)
  File "/Library/Python/2.7/site-packages/django/core/management/commands/syncdb.py", line 8, in <module>
    from django.core.management.sql import custom_sql_for_model, emit_post_sync_signal
  File "/Library/Python/2.7/site-packages/django/core/management/sql.py", line 6, in <module>
    from django.db import models
  File "/Library/Python/2.7/site-packages/django/db/__init__.py", line 11, in <module>
    if DEFAULT_DB_ALIAS not in settings.DATABASES:
  File "/Library/Python/2.7/site-packages/django/utils/functional.py", line 184, in inner
    self._setup()
  File "/Library/Python/2.7/site-packages/django/conf/__init__.py", line 40, in _setup
    raise ImportError("Settings cannot be imported, because environment variable %s is undefined." % ENVIRONMENT_VARIABLE)
ImportError: Settings cannot be imported, because environment variable DJANGO_SETTINGS_MODULE is undefined.

settings.py 和 manage.py 在同一个目录中,在添加这个插件之前我没有这个问题。

数据库部分的 settings.py 如下:

# Activate django-dbindexer for the default database
DATABASES['native'] = DATABASES['default']
DATABASES['default'] = {'ENGINE': 'dbindexer', 'TARGET': 'native'}
AUTOLOAD_SITECONF = 'indexes'

INSTALLED_APPS = (
#    'django.contrib.admin',
    'django.contrib.contenttypes',
    'django.contrib.auth',
    'django.contrib.sessions',
    'djangotoolbox',
    'autoload',
    'dbindexer',
    # social_auth
    'httplib2',
    'openid',
    'oauth2',
    'social_auth',
    #userena
    'userena',
    'guardian',
    'easy_thumbnails',
    'accounts',
    # djangoappengine should come last, so it can override a few manage.py commands
    'djangoappengine',
)

这是我一次运行服务器

BB8265:epapyri-django$ sudo django-admin.py runserver
Traceback (most recent call last):
  File "/usr/local/bin/django-admin.py", line 5, in <module>
    management.execute_from_command_line()
  File "/Library/Python/2.7/site-packages/django/core/management/__init__.py", line 443, in execute_from_command_line
    utility.execute()
  File "/Library/Python/2.7/site-packages/django/core/management/__init__.py", line 382, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/Library/Python/2.7/site-packages/django/core/management/__init__.py", line 261, in fetch_command
    klass = load_command_class(app_name, subcommand)
  File "/Library/Python/2.7/site-packages/django/core/management/__init__.py", line 69, in load_command_class
    module = import_module('%s.management.commands.%s' % (app_name, name))
  File "/Library/Python/2.7/site-packages/django/utils/importlib.py", line 35, in import_module
    __import__(name)
  File "/Library/Python/2.7/site-packages/django/core/management/commands/runserver.py", line 8, in <module>
    from django.core.servers.basehttp import AdminMediaHandler, run, WSGIServerException, get_internal_wsgi_application
  File "/Library/Python/2.7/site-packages/django/core/servers/basehttp.py", line 26, in <module>
    from django.views import static
  File "/Library/Python/2.7/site-packages/django/views/static.py", line 95, in <module>
    template_translatable = ugettext_noop(u"Index of %(directory)s")
  File "/Library/Python/2.7/site-packages/django/utils/translation/__init__.py", line 75, in gettext_noop
    return _trans.gettext_noop(message)
  File "/Library/Python/2.7/site-packages/django/utils/translation/__init__.py", line 48, in __getattr__
    if settings.USE_I18N:
  File "/Library/Python/2.7/site-packages/django/utils/functional.py", line 184, in inner
    self._setup()
  File "/Library/Python/2.7/site-packages/django/conf/__init__.py", line 40, in _setup
    raise ImportError("Settings cannot be imported, because environment variable %s is undefined." % ENVIRONMENT_VARIABLE)
ImportError: Settings cannot be imported, because environment variable DJANGO_SETTINGS_MODULE is undefined.

[编辑]

我从 INSTALL_APP 中删除了非 django 项目,将 django.models 导入到我的帐户/MyProfile 和 .datastore 上的 chmod 777,因为它不应该在每次修改它时都请求许可。

{ File "/git/ePapyri/epapyri-django/djangoappengine/db/base.py", line 160, in _value_for_db raise DatabaseError("Only strings and positive integers " django.db.utils.DatabaseError: Only strings and positive integers may be used as keys on GAE.}

4

2 回答 2

0

你为什么django-admin.py要运行syncdb和runserver?你应该使用manage.py.

你绝对不应该sudo用来运行其中任何一个。

(另请注意,您的 INSTALLED_APPS 似乎是无稽之谈:它包含大量普通的 Python 库,例如 httplib2 和 oauth2,它们根本不存在任何业务。)

已编辑

首先,您应该编辑您的问题以添加回溯。

其次,报错信息很明确:你还没有django.db.models在你的accounts/models.py文件中导入。

第三,在 INSTALLED_APPS 中包含非 Django 库仍然是无稽之谈。根本没有必要这样做。并且您的数据存储不应该首先使用 sudo 创建 - 要么删除并重新创建它,要么用于chmod使其可供普通用户访问。

于 2013-01-16T09:38:08.177 回答
0

我发现问题是通过向 GAE 中的库添加 PIL 来解决的,而 yaml 文件会解决问题,因为它抱怨 python 中的图像库。django 支持的所有库的链接是https://developers.google.com/appengine/docs/python/tools/libraries27,因此将所有需要的库添加到 .yaml 文件和 INSTALL_APP。

于 2013-01-18T06:50:01.067 回答