7

我可以浏览 django 管理员登录页面,但是在键入正确的登录详细信息后,它将保留在具有空文本框的同一登录页面上。如果登录详细信息错误,它将显示消息。我有以下内容,我可以通过哪些方式进行故障排除,因为日志没有说明任何重要内容。

在 shell 上测试登录的方法有哪些?

使用 manage.py createsuperuser 创建超级用户,因为我在运行 syncdb 期间错过了默认用户

清除cookies,重试还是一样。

在 settings.py 中更正 SITE_ID

settings.py
import logging 
import pwd
import os

DEBUG = True
TEMPLATE_DEBUG = DEBUG
DEBUG_TOOLBAR = False
PROFILER_ON = False
INTERNAL_IPS = (
'127.0.0.1'
)

ADMINS = (
    ('Admin', 'test@domain.com'),
)

SEND_BROKEN_LINK_EMAILS = False
MANAGERS = ADMINS

DEFAULT_FROM_EMAIL = 'test@domain'
SERVER_EMAIL = DEFAULT_FROM_EMAIL

EMAIL_HOST = 'test'

UPLOAD_ROOT = '/domain/uploads'

 PUBLIC_UPLOAD_ROOT = '/domain/htdocs/public_uploads'

DATABASES = {
'default': {
    'ENGINE': 'django.db.backends.mysql',
    'NAME': 'table_name',
    'USER': 'username',
    'PASSWORD': 'password',
    'HOST': 'localhost',
    'PORT': '',
    # use this to create InnoDB tables
    'OPTIONS': {
        'init_command': 'SET storage_engine=InnoDB',
        'charset': 'utf8',
    }
}
}

#SESSION_COOKIE_SECURE = True

# Setup logging
LOGGING = {
'version': 1,
'disable_existing_loggers': True,
}

TIME_ZONE = 'America/Chicago'

LANGUAGE_CODE = 'en-us'

LANGUAGES = (
  ('en-us', _('English(US)')),
)

SITE_ID = 1
SITE_NAME = 'my site'

USE_I18N = True

MEDIA_ROOT = os.path.join(os.path.dirname(__file__), 'media')

MEDIA_URL = '/media/'

PUBLIC_UPLOAD_URL = '/public_uploads/'

UPLOAD_URL = '/uploads/'


UPLOAD_IMAGES_DIR = 'images/'

ADMIN_MEDIA_PREFIX = '/djangomedia/'

SECRET_KEY = 'test'

#SESSION_COOKIE_HTTPONLY = True

#SESSION_COOKIE_DOMAIN = 'domain'

# List of callables that know how to import templates from various sources.
TEMPLATE_LOADERS = (
'django.template.loaders.filesystem.Loader',
'django.template.loaders.app_directories.Loader',
)
MIDDLEWARE_CLASSES = (
'django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.locale.LocaleMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.transaction.TransactionMiddleware',
'django.middleware.doc.XViewMiddleware',
'django.contrib.flatpages.middleware.FlatpageFallbackMiddleware',
)


LOGIN_URL = '/login/'

LOGIN_REDIRECT_URL = '/users/main/'
# The URL where requests are redirected for logout.
LOGOUT_URL = '/logout/'


TEMPLATE_CONTEXT_PROCESSORS = (
'django.contrib.auth.context_processors.auth',
'django.core.context_processors.i18n',
'django.core.context_processors.request',
'django.contrib.messages.context_processors.messages',
)


AUTHENTICATION_BACKENDS = (
'django.contrib.auth.backends.ModelBackend',
)

ROOT_URLCONF = 'myapp.urls'


TEMPLATE_DIRS = (
os.path.join(os.path.dirname(__file__), 'templates'),
)

INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.admin',
'django.contrib.admindocs',
'django.contrib.flatpages',
)

urls.py
url(r'^admin/', include(admin.site.urls)),
4

1 回答 1

6

这实际上是由于我的 settings.py 中的 SESSION_COOKIE_SECURE = True,我不小心在 2 个地方定义了它,一个评论了另一个未评论的地方,导致这种情况发生,因为该站点尚未在 https 下运行。这是个愚蠢的错误 – user1076881 4 月 5 日 7:27

于 2012-07-20T16:39:15.470 回答