1

Django プロジェクトをサーバーにデプロイしようとしています。が、使ってみるとDjango上の静的ファイルが正しく読み込めません

プロジェクトを Debian サーバーにデプロイします。もちろん同じサーバーの静的ファイルで、プロジェクトのデプロイに成功しました。しかし、css のような静的ファイルはまだプロジェクトに表示されません

これは私の設定ファイルです:

"""
Django settings for akun project.

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

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

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
import os
PROJECT_ROOT = os.path.abspath(os.path.dirname(__file__))
PROJECT_DIR = os.path.join(PROJECT_ROOT)


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

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = '8g*v#sf1i0y#+@5jyy$kk)wlixu*9yo(t$&1n%59ip*391sy@u'

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

TEMPLATE_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',
    'simofa',
    'accounts',
)

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

WSGI_APPLICATION = 'akun.wsgi.application'


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

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

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

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'Asia/Jakarta'

USE_I18N = True

USE_L10N = True

USE_TZ = True


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

STATIC_URL = '/static/'

# template location
TEMPLATE_DIRS = (
        os.path.join(os.path.dirname(PROJECT_ROOT), "static", "templates"),
        '/home/boss/kantor/akun/templates/', 
    )

if DEBUG:
    MEDIA_URL = '/media/'
    STATIC_ROOT = os.path.join(os.path.dirname(PROJECT_DIR),"static","static-only")
    MEDIA_ROOT = os.path.join(os.path.dirname(PROJECT_DIR),"static","media")
    STATICFILES_DIRS = os.path.join(os.path.dirname(PROJECT_DIR),"static","static"),

STATIC_URL='/static/'URLに変更しようとしてSTATIC_URL='http://www.url.com/my_project/static' いますが、結果はまだ表示されません

ローカルホストで試してみると、正しく動作します。

解決策は?

4

2 に答える 2

2

静的ファイル ディレクトリはタプルである必要があります

STATICFILES_DIRS = (
    os.path.join(BASE_DIR, 'static'),
)
于 2015-04-29T03:47:42.230 に答える