Django Admin(1.11.14)登录后显示404错误(www.mysite / admin / login /?next = / admin /)

时间:2018-08-11 07:21:34

标签: django postgresql django-admin passenger

我正在使用a2hosing passenger_wsgi.py 我的django版本是1.11.14,即使我可以看到django管理员登录页面,前端看起来也不错。但是,当我尝试以超级用户身份(当然使用有效的凭据)登录时,将我带到www.mysite/admin/login/?next=/admin/,错误为404

错误消息:

Page not found (404)
Request Method: POST
Request URL:    mysite/admin/login/?next=/admin/
Raised by:  django.contrib.admin.sites.login
Using the URLconf defined in mysite.urls, Django tried these URL patterns, in this order:

^admin/
The current path, login/,thing, match any of these.

最后,当从控制台(ssh)测试django-admin检查时,我也得到了:

ModuleNotFoundError: No module named 'mysite'

passenger_wsgi.py:

import sys, os
INTERP = "/home/newcoll1/virtualenv/public__html_mainsite/3.6/bin/python"
#INTERP is present twice so that the new python interpreter
#knows the actual executable path 
if sys.executable != INTERP: os.execl(INTERP, INTERP, *sys.argv)

cwd = os.getcwd()
sys.path.append(cwd)
sys.path.append(cwd + '/mysite')  #You must add your project here

sys.path.insert(0,cwd+'/virtualenv/public__html_mainsite/3.6/bin')
sys.path.insert(0,cwd+'/virtualenv/public__html_mainsite/3.6/lib/python3.6/site-packages')

# os.environ['DJANGO_SETTINGS_MODULE'] = 'mysite.settings'
from django.core.wsgi import get_wsgi_application

os.environ['DJANGO_SETTINGS_MODULE'] = 'mysite.settings'

application = get_wsgi_application()

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.11/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 = True

ALLOWED_HOSTS = ['*****','*****']


# Application definition

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

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

ROOT_URLCONF = 'newcollectiblefineart.urls'

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [],
        '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 = 'newcollectiblefineart.wsgi.application'


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

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

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql_psycopg2',
        'NAME': '*****',
        'USER': '*****',
        'PASSWORD': '*****',
        'HOST': 'localhost',
        'PORT': '*****'    

    }
}

# Password validation
# https://docs.djangoproject.com/en/1.11/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.11/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.11/howto/static-files/

STATIC_ROOT = '/home/newcoll1/public_html/mainsite/newcollectiblefineart/static/'

STATIC_URL = '/mainsite/newcollectiblefineart/static/'

urls.py:

from django.conf.urls import url, include 
from django.contrib import admin



urlpatterns = [
    url(r'^admin/', admin.site.urls),

]

0 个答案:

没有答案