django - 管理员登录错误" 500服务器错误"

时间:2016-05-16 16:52:59

标签: django http-status-code-500

我刚刚用django设置我的网站,所以我尝试登录我的/ admin页面,但服务器返回" 500服务器错误",我现在无法管理我的数据库。

apache日志没有错误,这就是浏览器控制台所说的:

Failed to load resource: the server responded with a status of 500 (Internal Server Error)
http://www.example.com/admin/login/?next=/admin/ 

我认为这部分网址真的很奇怪,我不确定:

/admin/login/?next=/admin/ 

这是我的urls.py文件:

from django.conf.urls import url
from django.contrib import admin
from Gestione import views

urlpatterns = [
    url(r'^admin/', admin.site.urls),
    url(r'^$', views.index),
    url(r'^faq', views.faq),
    url(r'^contacts', views.contacts),
]

我在ubuntu服务器15.04上使用apache 2.4.10和django 1.9.6

感谢您的帮助

编辑:settings.py

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
# See https://docs.djangoproject.com/en/1.9/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 = ['www.example.com','example.com']

# Application definition

INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'Gestione',
]

MIDDLEWARE_CLASSES = [
'django.middleware.security.SecurityMiddleware',
'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 = 'proj.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 = 'proj.wsgi.application'


# Database
# https://docs.djangoproject.com/en/1.9/ref/settings/#databases

DATABASES = {
'default': {
    'ENGINE': 'django.db.backends.sqlite3',
    'NAME': os.path.join(BASE_DIR, 'gestione.db'),
}
}


# Password validation
# https://docs.djangoproject.com/en/1.9/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.9/topics/i18n/

LANGUAGE_CODE = 'en-EN'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_L10N = True

USE_TZ = True


# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.9/howto/static-files/

STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'Gestione/static')

编辑2(django追溯):

Traceback:

File "/usr/local/lib/python3.4/dist-packages/django/db/backends/utils.py" in execute
  64.                 return self.cursor.execute(sql, params)

File "/usr/local/lib/python3.4/dist-packages/django/db/backends/sqlite3/base.py" in execute
  323.         return Database.Cursor.execute(self, query, params)

The above exception (unable to open database file) was the direct cause of the following exception:

File "/usr/local/lib/python3.4/dist-packages/django/core/handlers/base.py" in get_response
  149.                     response = self.process_exception_by_middleware(e, request)

File "/usr/local/lib/python3.4/dist-packages/django/core/handlers/base.py" in get_response
  147.                     response = wrapped_callback(request, *callback_args, **callback_kwargs)

File "/usr/local/lib/python3.4/dist-packages/django/contrib/admin/options.py" in wrapper
  541.                 return self.admin_site.admin_view(view)(*args, **kwargs)

File "/usr/local/lib/python3.4/dist-packages/django/utils/decorators.py" in _wrapped_view
  149.                     response = view_func(request, *args, **kwargs)

File "/usr/local/lib/python3.4/dist-packages/django/views/decorators/cache.py" in _wrapped_view_func
  57.         response = view_func(request, *args, **kwargs)

File "/usr/local/lib/python3.4/dist-packages/django/contrib/admin/sites.py" in inner
  244.             return view(request, *args, **kwargs)

File "/usr/local/lib/python3.4/dist-packages/django/contrib/admin/options.py" in change_view
  1440.         return self.changeform_view(request, object_id, form_url, extra_context)

File "/usr/local/lib/python3.4/dist-packages/django/utils/decorators.py" in _wrapper
  67.             return bound_func(*args, **kwargs)

File "/usr/local/lib/python3.4/dist-packages/django/utils/decorators.py" in _wrapped_view
  149.                     response = view_func(request, *args, **kwargs)

File "/usr/local/lib/python3.4/dist-packages/django/utils/decorators.py" in bound_func
  63.                 return func.__get__(self, type(self))(*args2, **kwargs2)

File "/usr/lib/python3.4/contextlib.py" in inner
  30.                 return func(*args, **kwds)

File "/usr/local/lib/python3.4/dist-packages/django/contrib/admin/options.py" in changeform_view
  1378.                 self.save_model(request, new_object, form, not add)

File "/usr/local/lib/python3.4/dist-packages/django/contrib/admin/options.py" in save_model
  991.         obj.save()

File "/usr/local/lib/python3.4/dist-packages/django/db/models/base.py" in save
  708.                        force_update=force_update, update_fields=update_fields)

File "/usr/local/lib/python3.4/dist-packages/django/db/models/base.py" in save_base
  736.             updated = self._save_table(raw, cls, force_insert, force_update, using, update_fields)

File "/usr/local/lib/python3.4/dist-packages/django/db/models/base.py" in _save_table
  801.                                       forced_update)

File "/usr/local/lib/python3.4/dist-packages/django/db/models/base.py" in _do_update
  851.         return filtered._update(values) > 0

File "/usr/local/lib/python3.4/dist-packages/django/db/models/query.py" in _update
  645.         return query.get_compiler(self.db).execute_sql(CURSOR)

File "/usr/local/lib/python3.4/dist-packages/django/db/models/sql/compiler.py" in execute_sql
  1149.         cursor = super(SQLUpdateCompiler, self).execute_sql(result_type)

File "/usr/local/lib/python3.4/dist-packages/django/db/models/sql/compiler.py" in execute_sql
  848.             cursor.execute(sql, params)

File "/usr/local/lib/python3.4/dist-packages/django/db/backends/utils.py" in execute
  79.             return super(CursorDebugWrapper, self).execute(sql, params)

File "/usr/local/lib/python3.4/dist-packages/django/db/backends/utils.py" in execute
  64.                 return self.cursor.execute(sql, params)

File "/usr/local/lib/python3.4/dist-packages/django/db/utils.py" in __exit__
  95.                 six.reraise(dj_exc_type, dj_exc_value, traceback)

File "/usr/local/lib/python3.4/dist-packages/django/utils/six.py" in reraise
  685.             raise value.with_traceback(tb)

File "/usr/local/lib/python3.4/dist-packages/django/db/backends/utils.py" in execute
  64.                 return self.cursor.execute(sql, params)

File "/usr/local/lib/python3.4/dist-packages/django/db/backends/sqlite3/base.py" in execute
  323.         return Database.Cursor.execute(self, query, params)

Exception Type: OperationalError at /admin/Gestione/game/5/change/
Exception Value: unable to open database file

1 个答案:

答案 0 :(得分:0)

您应该在此处发布 settings.py 文件,请记住删除所有敏感变量。我怀疑您收到错误是因为DEBUG = FalseALLOWED_HOSTS = []

尝试(暂时)设置ALLOWED_HOSTS = ['*']