在ubuntus上部署后,浏览器上没有显示Django

2024-10-02 08:18:54 发布

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

我已经使用apache2和modwsgi在个人ubuntu服务器上部署了我的django项目。但是我无法在浏览器上显示任何内容。它只在页面的角落显示“错误”。如果我做错了什么,请提出建议。你知道吗

我的设置.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__)))

SECRET_KEY = 'blah blah blah'

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

ALLOWED_HOSTS = []

ADMINS = (
    'surajitmishra@gmail.com',
)

# Application definition

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'mod_wsgi.server',
    'publications',
    '....',
    'crispy_forms',
    'widget_tweaks',
]

LOGGING = {
    'version': 1,
    'disable_existing_loggers': False,
    'handlers': {
        'console': {
            'class': 'logging.StreamHandler',
        },
    },
    'loggers': {
        'django': {
            'handlers': ['console'],
            'level': os.getenv('DJANGO_LOG_LEVEL', 'INFO'),
        },
    },
}

SITE_ID = 1

CRISPY_TEMPLATE_PACK = 'bootstrap3'

AUTH_USER_MODEL = 'user_profile.MyUser'

EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'  # During development only    

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 = 'pubnet.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',
            ],
        },
    },
]

REDIS_HOST = 'localhost'
REDIS_PORT = 6379
REDIS_DB = 0    

WSGI_APPLICATION = 'pubnet.wsgi.application'    

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql',
        'NAME': 'pubnet',
        'USER': 'root',
        'PASSWORD': 'password',
        'HOST': '127.0.0.1',   # Or an IP Address that your DB is hosted on
        'PORT': '3306',
    }
}    

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',
    },
]


IMAGE_TYPES = ['application/pdf; charset=binary',
               'text/plain;',
               'text/csv;', ]    

# 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_URL = '/static/'

STATIC_ROOT = os.path.join(BASE_DIR, 'static', 'static_root')

STATICFILES_DIRS = (
    os.path.join(BASE_DIR, 'static', 'static_dirs'),
)

MEDIA_URL = '/media/'

MEDIA_ROOT = os.path.join(BASE_DIR, 'media')

我的网址.py地址:

from django.conf.urls import include, url
from django.contrib import admin
from django.conf import settings
from django.views.generic.base import TemplateView
from django.conf.urls.static import static
from django.contrib.auth import views as auth_views
from django_filters.views import FilterView
from publications.filter import UserFilter

admin.autodiscover()

urlpatterns = [
    url(r'^admin/', admin.site.urls),
    url(r'^', include('publications.urls', namespace='publication')),
    ......

    url('^', include('django.contrib.auth.urls')),
    ]

if settings.DEBUG:
    urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
    urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

我的出版物/网址.py地址:

from django.conf.urls import url
from . import views
urlpatterns = [
    url(r'^$', views.index, name='index'),
    url(r'^pubnet/$', views.post_list, name='post_list'),
    .....        
]

/etc/apache2/可用站点/pubnet.conf文件地址:

<VirtualHost *:80>

        ServerName pubnet.com
        ServerAlias www.pubnet.com
        ServerAdmin root

        DocumentRoot /var/www/pubnet
        WSGIScriptAlias / /var/www/pubnet/pubnet/wsgi.py
        <Directory "/var/www/pubnet/pubnet/">
           Require all denied
        </Directory>

        <Directory "/var/www/pubnet/pubnet">
        <Files wsgi.py>
           Require all denied
        </Files>
        </Directory>

        ErrorLog /var/www/logs/error.log
        CustomLog /var/www/logs/custom.log combined

        Alias /media/ /var/www/pubnet/media/
        Alias /static/ /var/www/pubnet/static/

        <Directory /var/www/pubnet/static>
           Require all denied
        </Directory>

        <Directory /var/www/pubnet/media>
           Require all denied
        </Directory>

</VirtualHost>

/var/www/pubnet/pubnet/wsgi.py公司地址:

import os
import sys
import django.core.handlers.wsgi

# Calculate the path based on the location of the WSGI script.
apache_configuration= os.path.dirname(__file__)
project = os.path.dirname(apache_configuration)
workspace = os.path.dirname(project)
sys.path.append(workspace)
sys.path.append(project)

# Add the path to 3rd party django application and to django itself.
sys.path.append('/var/www/pubnet')
os.environ['DJANGO_SETTINGS_MODULE'] = 'pubnet.apache.override'

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "pubnet.settings")
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()

/var/log/apache2文件/错误.log地址:

[Thu Jul 27 15:23:32.498309 2017] [mpm_prefork:notice] [pid 30495] AH00163: Apache/2.4.7 (Ubuntu) PHP/5.5.9-1ubuntu4.21 mod_wsgi/3.4 Python/2.7.6 mod_perl/2.0.8 Perl/v5.18.2 configured -- resuming normal operations
[Thu Jul 27 15:23:32.498403 2017] [core:notice] [pid 30495] AH00094: Command line: '/usr/sbin/apache2'
[Thu Jul 27 16:30:29.106801 2017] [mpm_prefork:notice] [pid 30495] AH00169: caught SIGTERM, shutting down
[Thu Jul 27 16:33:32.680148 2017] [mpm_prefork:notice] [pid 21253] AH00163: Apache/2.4.7 (Ubuntu) PHP/5.5.9-1ubuntu4.21 mod_wsgi/3.4 Python/2.7.6 mod_perl/2.0.8 Perl/v5.18.2 configured -- resuming normal operations
[Thu Jul 27 16:33:32.680237 2017] [core:notice] [pid 21253] AH00094: Command line: '/usr/sbin/apache2'
[Thu Jul 27 17:19:21.703341 2017] [mpm_prefork:notice] [pid 21253] AH00169: caught SIGTERM, shutting down

我暂时保留了对pubnet目录的“777”权限。你知道吗

请帮忙。你知道吗


Tags: pathdjangofromimportauthwsgiosvar

热门问题