3
回答
Python static 静态资源显示500 INTERNAL SERVER ERROR
利用AWS快速构建适用于生产的无服务器应用程序,免费试用12个月>>>   

为什么Python 在我本机运行 ,加载不了static里面的的静态资源,显示500 INTERNAL SERVER ERROR,如下图:


而同样的代码 在同事那里运行,就可以成功!

求各位大神教教我~~~~

下面是我Python的 settings.py 配置

"""
Django settings for djangotest project.

For more information on this file, see
https://docs.djangoproject.com/en/1.6/topics/settings/

For the full list of settings and their values, see
https://docs.djangoproject.com/en/1.6/ref/settings/
"""

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
import os
import imp
import django.conf.global_settings as default_settings
#BASE_DIR = os.path.dirname(os.path.dirname(__file__))

# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/1.6/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'x3i)ktqp1_f5%e!766%-(^v0arq)^1mth%=25y35=cs_sak9xi'

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

ALLOWED_HOSTS = '*'

ADMINS = (
)

MANAGERS = ADMINS
# filesystems
PROJECT_DIR = os.path.dirname(os.path.abspath(__file__))

# static settings
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.6/howto/static-files/
STATIC_ROOT = os.path.join(PROJECT_DIR, 'static/')

STATIC_URL = '/static/'
STATICFILES_DIRS = (
   os.path.join(PROJECT_DIR, 'static/'),
)

# media settings
MEDIA_ROOT = os.path.join(STATIC_ROOT, 'media/')
MEDIA_URL = '/static/media/'

#templates files
TEMPLATE_DIRS = (
    os.path.join(PROJECT_DIR, 'templates/'),
)


# delete below if served by nginx
#STATIC_ROOT = ''

# Application definition

INSTALLED_APPS = (
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
)

MIDDLEWARE_CLASSES = (
    '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 = 'djangotest.urls'

WSGI_APPLICATION = 'djangotest.wsgi.application'


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

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql',
        'NAME': 'djangotest',
        'USER': 'root',
        'PASSWORD': 'wuzhi',
        'HOST': '127.0.0.1',
        'PORT': '3306',
    }
}

# Internationalization
# https://docs.djangoproject.com/en/1.6/topics/i18n/

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'Asia/Shanghai'

USE_I18N = True
USE_L10N = True
USE_TZ = True
APPEND_SLASH=False



下面是我 urls.py的配置

from django.conf.urls import patterns, include, url

from djangotest.view import indextest

from django.contrib.staticfiles.urls import staticfiles_urlpatterns




urlpatterns = patterns('',
    # Examples:
    # url(r'^$', 'djangotest.views.home', name='home'),
    # url(r'^blog/', include('blog.urls')),
    
    url(r'^indextest/$',indextest.as_view(), name='indextest')
)

# This will work if DEBUG is True
urlpatterns += staticfiles_urlpatterns()

#urlpatterns += staticfiles_urlpatterns()
from django.conf import settings
urlpatterns += patterns('',
   (r'^static/(?P<path>.*)$', 'django.views.static.serve', {'document_root': settings.STATIC_ROOT}),
)



举报
l_ALLE
发帖于4年前 3回/1K+阅
顶部