z6c - personal blog about topics

Christian Müller – Letzte Änderung: 06.08.2013 11:05 Uhr

Django mit wsgi über Apache laufen lassen inkl. Static Files und Admin Templates

Aus verschiedenen Quellen zusammengetragen

Vorbereitung:

pip install wsgiref

Von Django Docs "STATIC_URL als Alias definieren":

Link zur Quelle

STATIC_URL Default: None

URL to use when referring to static files located in STATIC_ROOT.

Example: "/site_media/static/" or "http://static.example.com/"

If not None, this will be used as the base path for media definitions and the staticfiles app.

It must end in a slash if set to a non-empty value.

Von Django Docs "How to use Django with Apache and mod_wsgi":

Link zur Quelle

Serving the admin files Note that the Django development server automagically serves the static files of the admin app, but this is not the case when you use any other server arrangement. You’re responsible for setting up Apache, or whichever media server you’re using, to serve the admin files.

The admin files live in (django/contrib/admin/media/admin) of the Django distribution.

We strongly recommend using django.contrib.staticfiles to handle the admin files (this means using the collectstatic management command to collect the static files in STATIC_ROOT, and then configuring your webserver to serve STATIC_ROOT at STATIC_URL), but here are two other approaches:

Create a symbolic link to the admin static files from within your document root. Or, copy the admin static files so that they live within your Apache document root.

Von StackOverflow:

Link zur Quelle

1.: Virtual Host
<VirtualHost *:80>
    ServerAdmin webadmin@publisy.com
    ServerName alpha101.publisy.com
    DocumentRoot /var/www/mysite

    WSGIScriptAlias / /usr/local/django/mysite/apache/django.wsgi
    Alias /static/ /var/www/mysite/media/static/
    <Directory /var/www/mysite/media/static>
        Order deny,allow
        Allow from all
    </Directory>

    Alias /media/ /var/www/mysite/media/
    <Directory /var/www/mysite/media>
        Order deny,allow
        Allow from all
    </Directory>

    ErrorLog /var/log/apache2/error.log

    # Possible values include: debug, info, notice, warn, error, crit,
    # alert, emerg.
    LogLevel warn

    CustomLog /var/log/apache2/access.log combined

</VirtualHost>
2.: wsgi script (located at /usr/local/django/mysite/apache/django.wsgi)
import os, sys
sys.path.append('/usr/local/django')

sys.path.append('/var/www')
sys.path.append('/var/www/mysite')

os.environ['DJANGO_SETTINGS_MODULE'] = 'mysite.settings'

import django.core.handlers.wsgi

application = django.core.handlers.wsgi.WSGIHandler()

Kommentare für diesen Artikel noch nicht freigeschaltet.

Bitte eine Email an kommentare@zentonic.org mit Betreff "Kommentare für Post 53"