如何让静态文件在服务器上运行

时间:2016-07-29 01:51:42

标签: django django-staticfiles

我正在关注pythonprogramming.net Django教程,我真的对静态文件部分感到困惑。当我在本地运行它时它工作,但css不在服务器上工作。我正在跑步

nano /etc/nginx/sites-available/django

它返回别名/ home / django / django_project / django_project / media 我将其放入STATIC_ROOT变量中。然后当我跑

   python manage.py collectstatic

它说它们已被复制到静态位置,但是当我刷新ip时它不会显示它们。

这里是源代码

import os
BASE_DIR = os.path.dirname(os.path.dirname(__file__))

SECRET_KEY = 'It's secret'


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',
    'blog',
    'personal',
)

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 = 'django_project.urls'

WSGI_APPLICATION = 'django_project.wsgi.application'


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

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

# Internationalization
# https://docs.djangoproject.com/en/1.6/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.6/howto/static-files/
STATIC_ROOT='/home/django/django_project/django_project/media;'
STATIC_URL = '/static/'

0 个答案:

没有答案