gpt4 book ai didi

python - 无法启动 Django 游戏化服务器 - DJANGO_SETTINGS_MODULE

转载 作者:太空狗 更新时间:2023-10-29 11:37:04 27 4
gpt4 key购买 nike

我的任务是在我们的部门启动和运行游戏化以激励员工。

我找到了这个 https://github.com/ngageoint/gamification-server这是NGA发布的开源游戏化服务器。

我已严格按照所有说明进行操作,但无法启动服务器。

一些信息:
平台 - Ubuntu 14 LTS
开始游戏化之前安装的软件包:
PostgreSQL
Python Python-dev
混帐
虚拟环境

我能够安装依赖项,但是当我转到第二个任务“paver createdb”时,出现以下错误:

---> pavement.createdb


Captured Task Output:
---------------------

---> pavement.createdb
Traceback (most recent call last):
File "/root/pyenv/gamification/local/lib/python2.7/site-packages/paver/tasks.p y", line 195, in _run_task
return do_task()
File "/root/pyenv/gamification/local/lib/python2.7/site-packages/paver/tasks.p y", line 192, in do_task
return func(**kw)
File "pavement.py", line 87, in createdb
from gamification import settings
File "/etc/gamification-server/gamification/__init__.py", line 3, in <module>
from gamification.core.models import Points
File "/etc/gamification-server/gamification/core/models.py", line 27, in <modu le>
from django.contrib.auth.models import User
File "/root/pyenv/gamification/local/lib/python2.7/site-packages/django/contri b/auth/__init__.py", line 7, in <module>
from django.middleware.csrf import rotate_token
File "/root/pyenv/gamification/local/lib/python2.7/site-packages/django/middle ware/csrf.py", line 14, in <module>
from django.utils.cache import patch_vary_headers
File "/root/pyenv/gamification/local/lib/python2.7/site-packages/django/utils/ cache.py", line 26, in <module>
from django.core.cache import caches
File "/root/pyenv/gamification/local/lib/python2.7/site-packages/django/core/c ache/__init__.py", line 34, in <module>
if DEFAULT_CACHE_ALIAS not in settings.CACHES:
File "/root/pyenv/gamification/local/lib/python2.7/site-packages/django/conf/_ _init__.py", line 48, in __getattr__
self._setup(name)
File "/root/pyenv/gamification/local/lib/python2.7/site-packages/django/conf/_ _init__.py", line 42, in _setup
% (desc, ENVIRONMENT_VARIABLE))
ImproperlyConfigured: Requested setting CACHES, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings.

我已经按照说明配置了 settings.py 文件,并根据需要安装了所有包和依赖项,但完全没有任何进展。

设置.py

import os

PROJECT_ROOT = os.path.abspath(os.path.join(os.path.dirname(__file__), os.pardir))
PACKAGE_ROOT = os.path.abspath(os.path.dirname(__file__))
SITE_ROOT = os.path.dirname(os.path.realpath(__file__))

DEBUG = True
TEMPLATE_DEBUG = DEBUG

ADMINS = [
# ("Your Name", "your_email@example.com"),
]

MANAGERS = ADMINS

DATABASES = {
"default": {
"ENGINE": "django.db.backends.postgresql_psycopg2",
"NAME": "gamification",
"USER": "game_manager",
"PASSWORD": "django-gamification",
"HOST": "localhost",
"PORT": "5432"
}
}

# Local time zone for this installation. Choices can be found here:
# http://en.wikipedia.org/wiki/List_of_tz_zones_by_name
# although not all choices may be available on all operating systems.
# On Unix systems, a value of None will cause Django to use the same
# timezone as the operating system.
# If running in a Windows environment this must be set to the same as your
# system time zone.
TIME_ZONE = "UTC"

# Language code for this installation. All choices can be found here:
# http://www.i18nguy.com/unicode/language-identifiers.html
LANGUAGE_CODE = "en-us"

SITE_ID = 1

# If you set this to False, Django will make some optimizations so as not
# to load the internationalization machinery.
USE_I18N = True

# If you set this to False, Django will not format dates, numbers and
# calendars according to the current locale.
USE_L10N = True

# If you set this to False, Django will not use timezone-aware datetimes.
USE_TZ = True

# Absolute filesystem path to the directory that will hold user-uploaded files.
# Example: "/home/media/media.lawrence.com/media/"
#MEDIA_ROOT = os.path.join(PACKAGE_ROOT, "site_media", "media")

# URL that handles the media served from MEDIA_ROOT. Make sure to use a
# trailing slash.
# Examples: "http://media.lawrence.com/media/", "http://example.com/media/"
# MEDIA_URL = "/site_media/media/"

# Absolute path to the directory static files should be collected to.
# Don"t put anything in this directory yourself; store your static files
# in apps" "static/" subdirectories and in STATICFILES_DIRS.
# Example: "/home/media/media.lawrence.com/static/"
#STATIC_ROOT = '{0}'.format('/var/www/static')
STATIC_ROOT = os.path.join(PACKAGE_ROOT, "static")
MEDIA_ROOT = os.path.join(PROJECT_ROOT, "gamification/site_media")

# URL prefix for static files.
# Example: "http://media.lawrence.com/static/"
STATIC_URL = "/static/"

# Additional locations of static files
#STATICFILES_DIRS = [
# os.path.join(PACKAGE_ROOT, "static"),
#]

# List of finder classes that know how to find static files in
# various locations.
STATICFILES_FINDERS = [
"django.contrib.staticfiles.finders.FileSystemFinder",
"django.contrib.staticfiles.finders.AppDirectoriesFinder",
]

# Make this unique, and don't share it with anybody.
SECRET_KEY = "z7lz3v!zl9yohg2(yfk0!cmv)#lkl6znja*hh877b&byujuu7875vfr"

# List of callables that know how to import templates from various sources.
TEMPLATE_LOADERS = [
"django.template.loaders.filesystem.Loader",
"django.template.loaders.app_directories.Loader",
]

TEMPLATE_CONTEXT_PROCESSORS = [
"django.contrib.auth.context_processors.auth",
"django.core.context_processors.debug",
"django.core.context_processors.i18n",
"django.core.context_processors.media",
"django.core.context_processors.static",
"django.core.context_processors.tz",
"django.core.context_processors.request",
"django.contrib.messages.context_processors.messages",
"account.context_processors.account",
"pinax_theme_bootstrap.context_processors.theme",
]


MIDDLEWARE_CLASSES = [
"django.middleware.common.CommonMiddleware",
"django.contrib.sessions.middleware.SessionMiddleware",
"django.contrib.auth.middleware.AuthenticationMiddleware",
"corsheaders.middleware.CorsMiddleware",
"django.contrib.messages.middleware.MessageMiddleware",
]

ROOT_URLCONF = "gamification.urls"

# Python dotted path to the WSGI application used by Django's runserver.
WSGI_APPLICATION = "gamification.wsgi.application"

TEMPLATE_DIRS = [
os.path.join(PACKAGE_ROOT, "templates"),
]

REST_FRAMEWORK = {
# hyperlinked styles by default
# only used if the 'serializer_class' attribute is not set on view
'DEFAULT_MODEL_SERIALIZER_CLASS': 'rest_framework.serializers.HyperlinkedModelSerializer',

# Use Django's standard 'django.contrib.auth' permissions, or read-only for unauthorized users
# 'DEFAULT_PERMISSION_CLASSES': ['rest_framework.permissions.DjangoModelPermissionsOrAnonReadOnly']
}

INSTALLED_APPS = [
"django.contrib.admin",
"django.contrib.auth",
"django.contrib.contenttypes",
"django.contrib.sessions",
"django.contrib.sites",
"django.contrib.messages",
"django.contrib.staticfiles",

# theme
"pinax_theme_bootstrap",
"django_forms_bootstrap",

# external
"account",
"metron",
"eventlog",
"bootstrap3",
"south",
"rest_framework",
"corsheaders",
"mptt",

# project
"gamification",
"gamification.badges",
"gamification.core",
"gamification.events",
]

# A sample logging configuration. The only tangible logging
# performed by this configuration is to send an email to
# the site admins on every HTTP 500 error when DEBUG=False.
# See http://docs.djangoproject.com/en/dev/topics/logging for
# more details on how to customize your logging configuration.
LOGGING = {
"version": 1,
"disable_existing_loggers": False,
"filters": {
"require_debug_false": {
"()": "django.utils.log.RequireDebugFalse"
}
},
"handlers": {
"mail_admins": {
"level": "ERROR",
"filters": ["require_debug_false"],
"class": "django.utils.log.AdminEmailHandler"
}
},
"loggers": {
"django.request": {
"handlers": ["mail_admins"],
"level": "ERROR",
"propagate": True,
},
}
}

FIXTURE_DIRS = [
os.path.join(PROJECT_ROOT, "fixtures"),
]

EMAIL_BACKEND = "django.core.mail.backends.console.EmailBackend"

ACCOUNT_OPEN_SIGNUP = True
ACCOUNT_USE_OPENID = False
ACCOUNT_REQUIRED_EMAIL = False
ACCOUNT_EMAIL_VERIFICATION = False
ACCOUNT_EMAIL_AUTHENTICATION = False
ACCOUNT_LOGIN_REDIRECT_URL = "home"
ACCOUNT_LOGOUT_REDIRECT_URL = "home"
ACCOUNT_EMAIL_CONFIRMATION_EXPIRE_DAYS = 2

AUTHENTICATION_BACKENDS = [
"account.auth_backends.UsernameAuthenticationBackend",
]

CORS_ORIGIN_WHITELIST = ( '192.168.5.131:8000', 'localhost:8000', )
CORS_ALLOW_METHODS = ( 'GET', 'POST', 'OPTIONS' )

CACHES = {
'default': {
'BACKEND': 'django.core.cache.backends.locmem.LocMemCache',
}
}

更新——对于任何发现此代码并为同样的事情苦苦挣扎的人。在任务 createdb 和 create_db_user 下的 pavement.py 文件中,我添加了以下两行

import os
os.environ["DJANGO_SETTINGS_MODULE"]="gamification.settings"

--更新--

终于搞定了。似乎在游戏化服务器的设置中缺少几个步骤。

在发布 Paver createdb 之前,我运行了 paver install_fixturepaver sync_initial 这为我解决了问题,服务器现在运行良好

最佳答案

好的,我自己设法解决了这个问题。如果有人找到此代码并想将其用作游戏化服务器,请按照以下步骤操作:

  1. 设置您的操作系统(我使用的是 Linux Ubuntu)
  2. 安装python、postgresql、git、pip、libpq-dev
  3. 创建并激活虚拟环境
  4. 将代码克隆到您的 cwd
  5. 安装摊铺机
  6. 安装依赖
  7. 运行命令 paver sync_initial,paver install_fixture
  8. 摊铺机创建b
  9. 摊铺机 create_db_user
  10. python manage.py createsuperuser
  11. python manage.py runserver

这应该能让事情顺利进行。请参阅我的原始帖子,了解我对某些文件所做的更改,这也有助于正确设置服务器。

关于python - 无法启动 Django 游戏化服务器 - DJANGO_SETTINGS_MODULE,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29791051/

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