2017-11-18 200 views
-2

我已經在谷歌計算引擎上部署了我的Django(1.10)網站,一切工作正常,但突然之間我的模型在管理中投擲500服務器錯誤。 我搜索了一下,但找不到任何解決方案。 所有其他模型在django管理中正常顯示,除了一個,這是TaggedArticles模型。 Idon't已經改變了我的網站的任何東西,可能是錯誤的?因爲它突然發生在我的網站上。django生產500服務器錯誤管理員用戶相關模型

這裏是我的代碼:

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 

這裏的標籤條的模式:

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) 

更新: 當我設置調試= 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

+0

\你得到了什麼錯誤信息? – 2017-11-18 05:43:13

+0

服務器錯誤(500) –

+0

如果不知道錯誤是什麼,我們無法幫助您。您應該在您的站點上配置[日誌記錄](https://docs.djangoproject.com/en/1.11/topics/logging/),以便可以追蹤錯誤的來源。 – solarissmoke

回答

0

這可能是一個mysql時區的問題。這是假設你有錯誤所需的庫。

檢查下面的值是否已經在[mysqld]部分的/etc/mysql/my.cnf中設置(在該標籤之後)。 FI沒有,進入它,然後重新啓動

`default-time-zone = 'UTC`' 

一旦你做到這一點,它仍然does not工作嘗試做上述後沖洗。

mysql> flush tables; 
相關問題