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

2024-09-22 14:20:13 发布

您现在位置:Python中文网/ 问答频道 /正文

我在google计算引擎上部署了Django(1.10)站点,一切正常,但是突然我的一个模型在管理中抛出了500个服务器错误。 我在谷歌上搜索了一下,但找不到任何解决办法。 所有其他模型都在django管理中正确显示,只有一个是TaggedArticles模型。 我没有改变我的网站上的任何东西,可能有什么不对?我的网站突然出现了这种情况。在

我的代码是:

设置.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的模型:

^{pr2}$

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)

这是管理员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时,它返回以下错误:

ValueError at /admin/users/taggedarticle/ Database returned an invalid datetime value. Are time zone definitions for your database and pytz installed? Request Method: GET Request URL: http://www.brainresearchtagging.com/admin/users/taggedarticle/ Django Version: 1.10.5 Exception Type: ValueError Exception Value:
Database returned an invalid datetime value. Are time zone definitions for your database and pytz installed? Exception Location: /root/virEnv/lib/python3.6/site-packages/django/db/models/functions/datetime.py in convert_value, line 181 Python Executable: /root/virEnv/bin/python3.6 Python Version: 3.6.1 Python Path:
['/root/brain', '/root/brain/brain', '/root/virEnv/bin', '/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'] Server time: Sat, 18 Nov 2017 11:55:01 +0000


Tags: pathdjangocomauthtrueosmodelslib
1条回答
网友
1楼 · 发布于 2024-09-22 14:20:13

这可能是mysql时区问题。这是假设您有来自错误的所需库。在

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

`default-time-zone = 'UTC`'

一旦你这样做,它仍然不起作用,尝试冲洗后,做上述。在

^{pr2}$

相关问题 更多 >