質問

I am running Ubuntu 14.04 on my notebook and I am using Django 1.6.4 (with virtualenv) together with Apache 2.4.7.

I have set up a django project that is located under my home directory in /home/nick/Workspace/Web/kleyboldt_django (kleyboldt is the name of the guy I am writing this project for). This folder contains my virtual env folder (django and south installed), my kleyboldt.wsgi and the actual project called kleyboldt_homepage. To make my site ready for production I wrote a config file to create a VirtualHost serving this site:

/etc/apache2/sites-available/mks.conf

WSGIDaemonProcess mks.com python-path=/home/nick/Workspace/Web/kleyboldt_django/kleyboldt_homepage:/home/nick/Workspace/Web/kleyboldt_django/env/lib/python2.7/site-packages
WSGIProcessGroup mks.com

<VirtualHost *:80>
    Alias /robots.txt /home/nick/Workspace/Web/kleyboldt_django/kleyboldt_homepage/static/robots.txt
    Alias /favicon.ico /home/nick/Workspace/Web/kleyboldt_django/kleyboldt_homepage/static/favicon.ico

    AliasMatch ^/([^/]*\.css) /home/nick/Workspace/Web/kleyboldt_django/kleyboldt_homepage/static-only/css/$1

    Alias /media/ /home/nick/Workspace/Web/kleyboldt_django/kleyboldt_homepage/static/media/
    Alias /static/ /home/nick/Workspace/Web/kleyboldt_django/kleyboldt_homepage/static/static/

    Alias /static/admin/ /home/nick/Workspace/Web/kleyboldt_django/env/lib/python2.7/site-packages/django/contrib/admin/static/admin/

    <Directory /home/nick/Workspace/Web/kleyboldt_django/kleyboldt_homepage/static/static>
        Require all granted
    </Directory>

    <Directory /home/nick/Workspace/Web/kleyboldt_django/kleyboldt_homepage/static/media>
        Require all granted
    </Directory>

    WSGIScriptAlias / /home/nick/Workspace/Web/kleyboldt_django/kleyboldt.wsgi

    ServerName mks.com

    Alias /static /home/nick/Workspace/Web/kleyboldt_django/kleyboldt_homepage/static

    <Directory /home/nick/Workspace/Web/kleyboldt_django/>
        Require all granted
        Order allow,deny
        Allow from all
    </Directory>

    <Directory /home/nick/Workspace/Web/kleyboldt_django/env/lib/python2.7/site-packages/>
        Require all granted
        Order allow,deny
        Allow from all
    </Directory>
</VirtualHost>

I edited /etc/hosts in order to redirect mks.com to my local maschine. The settings file looks like that:

/home/nick/Workspace/Web/kleyboldt_django/kleyboldt_homepage/kleyboldt_homepage/settings.py

import os
BASE_DIR = os.path.dirname(os.path.dirname(__file__))
...
MEDIA_ROOT = os.path.join(BASE_DIR, 'static', 'media')

MEDIA_URL = '/media/'

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

STATIC_URL = '/static/'

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

TEMPLATE_DIRS = (
    os.path.join(BASE_DIR, 'static', 'templates'),
)

ADMIN_MEDIA_PREFIX = '/static/admin/'

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

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',
)
...

In kleyboldt_homepage/static/ are four folder: media (data uploaded by the user which you should not trust), static (folders css, fonts, img and js for Bootstrap), static-only (contains admin, css, fonts, img and jsafter ./manage.py collectstatic) and templates.

Unfortunately my admin site is still without css and opening the css files in the source code leads to an error message.

役に立ちましたか?

解決

run python manage.py collectstatic after setting up STATIC_ROOT and STATIC_URL in your settings.py

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top