管理员中用户相关模型的生产500服务器错误django

时间:2017-11-18 05:36:58

标签: python django python-3.x django-models django-admin

我已经在谷歌计算引擎上部署了我的Django(1.10)网站,一切正常,但突然之一我的模型在管理员中抛出了500服务器错误。 我已经google了一下,但无法找到任何解决方案。 所有其他模型都在django admin中正确显示,只有一个和那个TaggedArticles模型。 Idon没有改变我网站上的任何内容,可能出错了什么?因为它突然发生在我的网站上。

这是我的代码:

settings.py:

"""
Django settings for brain project.

Generated by 'django-admin startproject' using Django 1.10.5.

For more information on this file, see
https://docs.djangoproject.com/en/1.10/topics/settings/

For the full list of settings and their values, see
https://docs.djangoproject.com/en/1.10/ref/settings/
"""

import os


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


# Quick-start development settings - unsuitable for production
# For a test push to trigger build from codeship.
# Second thing for CodeShip deployment push
# See https://docs.djangoproject.com/en/1.10/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = '*******************'

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

ALLOWED_HOSTS = ['127.0.0.1', '35.202.165.136', 'brainresearchtagging.com', 'www.brainresearchtagging.com', ]
# INTERNAL_IPS = ['127.0.0.1']


# Application definition

INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'debug_toolbar',
'users',
'article',
'import_export',
]

MIDDLEWARE = [
    'django.middleware.security.SecurityMiddleware',
    'whitenoise.middleware.WhiteNoiseMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    'debug_toolbar.middleware.DebugToolbarMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
]


ROOT_URLCONF = 'brain.urls'

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [os.path.join(BASE_DIR, 'templates')]
        ,
        'APP_DIRS': True,
        'OPTIONS': {
            'context_processors': [
                'django.template.context_processors.debug',
                'django.template.context_processors.request',
                'django.contrib.auth.context_processors.auth',
                'django.contrib.messages.context_processors.messages',
            ],
        },
    },
]

WSGI_APPLICATION = 'brain.wsgi.application'

# DATABASES = {
DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql',
        'NAME': 'DB_NAME',
        'USER': 'DB_USERNAME',
        'PASSWORD': 'DB_PASS',
        'HOST': 'localhost',
        'PORT': '',
        }
}


#Static Storage
STATICFILES_STORAGE = 'whitenoise.django.GzipManifestStaticFilesStorage'

# Password validation
# https://docs.djangoproject.com/en/1.10/ref/settings/#auth-password-    validators

AUTH_PASSWORD_VALIDATORS = [
    {
        'NAME':    'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
    },
    {
        'NAME':    'django.contrib.auth.password_validation.NumericPasswordValidator',
    },
]


# Internationalization
# https://docs.djangoproject.com/en/1.10/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.10/howto/static-files/

STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')
STATIC_URL = '/assets/'
STATICFILES_DIRS = [os.path.join(BASE_DIR, 'assets'), ]


# Authentication
LOGIN_URL = 'users:login'
LOGIN_REDIRECT_URL = 'users:dashboard'

EMAIL_BACKEND = 'django.core.mail.backends.filebased.EmailBackend'
EMAIL_FILE_PATH = os.path.join(BASE_DIR, 'emails')

# Django Import-Export
IMPORT_EXPORT_USE_TRANSACTIONS = True

以下是Tagged Article的模型:

choices = (
('yes', 'Yes'),
('no', 'No'),
('not sure', 'Not Sure'),

class TaggedArticle(models.Model):
    user = models.ForeignKey(User, related_name='tagging')
    email = models.EmailField(max_length=255)
    category_fit = models.CharField(choices=choices, max_length=255)
    article = models.ForeignKey(Article, related_name='articles')
    link = models.URLField(max_length=255,)
    relevant_feedback = models.TextField(blank=True)
    category = models.CharField(max_length=255,)
    created_at = models.DateTimeField(default=timezone.now, editable=False)

这里的admin.py:

class TaggedArticleAdmin(admin.ModelAdmin):
date_hierarchy = 'created_at'
fields = ['category_fit', 'article', 'link', 'relevant_feedback', 'category', 'user', 'email']
list_display = ['article', 'link', 'user', 'email', 'relevant_feedback']
list_filter = ['user', 'email']
model = TaggedArticle


admin.site.register(Tagged, TaggedArticleAdmin)

更新 当我设置debug = True时,它会返回以下错误:

  

/ admin / users / taggedarticle /的ValueError   数据库返回了无效的日期时间值。是否安装了数据库和pytz的时区定义?   请求方法:GET   请求网址:http://www.brainresearchtagging.com/admin/users/taggedarticle/   Django版本:1.10.5   异常类型:ValueError   例外价值:
  数据库返回了无效的日期时间值。是否安装了数据库和pytz的时区定义?   异常位置:/root/virEnv/lib/python3.6/site-packages/django/db/models/functions/datetime.py in convert_value,第181行   Python可执行文件:/root/virEnv/bin/python3.6   Python版本:3.6.1   Python路径:
  [' /根/脑&#39 ;,    ' /根/脑/脑&#39 ;,    ' /根/ virEnv / bin中&#39 ;,    ' /root/virEnv/lib/python36.zip' ;,    ' /root/virEnv/lib/python3.6' ;,    ' /root/virEnv/lib/python3.6/lib-dynload' ;,    ' /usr/local/lib/python3.6' ;,    ' /root/virEnv/lib/python3.6/site-packages' ;,    ' /root/virEnv/lib/python3.6/site-packages/odf' ;,    ' /root/virEnv/lib/python3.6/site-packages/odf' ;,    ' /root/virEnv/lib/python3.6/site-packages/odf' ;,    ' /root/virEnv/lib/python3.6/site-packages/odf' ;,    ' /root/virEnv/lib/python3.6/site-packages/odf' ;,    ' /root/virEnv/lib/python3.6/site-packages/odf' ;,    ' /root/virEnv/lib/python3.6/site-packages/odf']   服务器时间:周六,2017年11月18日11:55:01 +0000

1 个答案:

答案 0 :(得分:0)

这可能是一个mysql时区问题。这假设你有错误所需的库。

检查[mysqld]部分中的/etc/mysql/my.cnf中是否已设置以下值(在该标记之后)。 FI否,输入然后重新启动

`default-time-zone = 'UTC`'

一旦你这样做了它仍然无法工作,请在完成上述操作后进行冲洗。

mysql> flush tables;