【问题标题】:I have deployed my django project in pythonanywhere, DATABASES is improperly configured error我已经在 pythonanywhere 部署了我的 django 项目,DATABASES 配置不正确错误
【发布时间】:2015-05-10 22:11:53
【问题描述】:

我已经在 pythonanywhere 中部署了我的 django 项目,不需要任何数据库,我收到错误 - DATABASES is proper configured 。我部署的项目的链接是 -http://drchitradhawle.pythonanywhere.com/

我的setting.py文件是-

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
import os
BASE_DIR = os.path.dirname(os.path.dirname(__file__))


# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/1.7/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'fi+9_egiio(7l6xvbgk%o=!k(ktn3!ywhc4+p_6^57j4yvl0tp'


# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

TEMPLATE_DEBUG = True

ALLOWED_HOSTS = []


# Application definition

INSTALLED_APPS = (
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'webpage',
)

MIDDLEWARE_CLASSES = (
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
)

ROOT_URLCONF = 'website.urls'

WSGI_APPLICATION = 'website.wsgi.application'


# Database
# https://docs.djangoproject.com/en/1.7/ref/settings/#databases
DATABASES = {}

# Internationalization
# https://docs.djangoproject.com/en/1.7/topics/i18n/

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_L10N = True

USE_TZ = True

# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.7/howto/static-files/
STATIC_ROOT = "/home/DrChitraDhawle/website/webpage/static"
STATIC_URL = '/static/'
STATICFILES_DIR = (
    ('assets', '/home/DrChitraDhawle/website/webpage'),
    )
#
#STATICFILES_DIR = [os.path.join(BASE_DIR, '')]

MEDIA_URL = 'http://localhost:8085/media/'

【问题讨论】:

标签: django database python-2.7 deployment pythonanywhere


【解决方案1】:

Django 需要一个数据库来存储会话/cookie 信息等信息。因此,即使您不将数据库用于您自己的网站内容,您仍然需要一个。

幸运的是,只需使用默认的 sqlite 设置,然后运行 ​​./manage.py syncdb 就足以让现在一切正常。

【讨论】:

    【解决方案2】:

    虽然你不想在你的项目中使用数据库,但你仍然必须像@conrad 所说的那样给出数据库定义。因此,您可以使用 sqlite3,这是一个基于文件的数据库,不需要设置数据库帐户和密码。

    将您的数据库设置设置为 -

     DATABASES = {
                  'default': {
                       'ENGINE': 'django.db.backends.sqlite3',
                       'NAME': '/home/<username>/<ProjectName>/db.sqlite',
                       'USER': '',
                       'PASSWORD': '',
                       'HOST': '',
                       'PORT': ''
                   }
              }
    

    然后在控制台中运行以下命令 -

     python ./manage.py syncdb
    

    现在将要求您输入密码、用户名和电子邮件 ID,以便为数据库创建超级用户。 一切都完成了!

    【讨论】:

      猜你喜欢
      • 2019-09-26
      • 1970-01-01
      • 2015-04-30
      • 2021-03-25
      • 1970-01-01
      • 2020-03-07
      • 2021-12-20
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多