阿帕奇不提供Django管理静态文件 [英] Apache not serving django admin static files

查看:159
本文介绍了阿帕奇不提供Django管理静态文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

让我感谢你们在堆栈溢出社会对我的帮助与各种Django和阿帕奇(与mod_wsgi的)错误。我问大约5相关的问题,到目前为止,现在我越来越近,这是让我的内容出在生产现场!

Let me thanks you guys at the Stack Overflow community for helping me with various Django and Apache (with mod_wsgi) errors. I've asked about 5 related questions so far and now I'm getting closer and closer to getting my content out on a production site!

所以我知道有这个很多类似的问题,我已经读了一堆 <一href=\"http://stackoverflow.com/questions/3043868/problem-with-django-styling\"> href=\"http://stackoverflow.com/questions/6402185/serving-static-files-while-running-djangomod-wsgi-on-apache-2-2\">questions <一href=\"http://stackoverflow.com/questions/3271731/djangos-admin-pages-are-missing-their-typical-formatting-style-have-i-set-it-u\">about ​​服务 <一个href=\"http://stackoverflow.com/questions/6073916/problems-linking-to-static-files-in-django-1-3\">static <一href=\"http://stackoverflow.com/questions/5396552/problem-applying-css-in-django-with-static-files-app\">media 文件 <一个href=\"http://stackoverflow.com/questions/5687136/static-media-fails-to-load-in-django\">Django.

So I know there are many similar questions about this and I have read a bunch of questions about serving static media files on Django.

我读 STATIC_URL STATIC_ROOT 时,(即将过时) ADMIN_MEDIA_ preFIX ,并设定别名/媒体/ ... 在Apache配置。我试图通过一个测试出每个解决方案之一,但我无法得到任何工作。

I read about STATIC_URL, STATIC_ROOT, the (soon to be obsolete) ADMIN_MEDIA_PREFIX, and setting a Alias /media/ ... in the Apache configuration. I tried to test out each solution one by one, but I couldn't get anything working.

下面是我的管理网站看起来像现在

Here is what my admin site looks like right now

我也有,其中任何子作品在我的服务器上的一个奇怪的情况。比如我试图建立我的服务器,让 http://www.satoshi.example.com/ 将使我的正常(非Django的)内容,而 http://django.satoshi.example.com/ 的将允许我的Django的内容到送达。但目前的子域,无论是satoshi.example.com或blahblahasdas.satoshi.example.com正在服刑我Django的文件(我知道,因为我可以去 /管理员页这两个网站,虽然他们会在不同的会话)。

I'm also having a weird case where any subdomain works on my server. For example I was trying to set up my server so that http://www.satoshi.example.com/ would allow my normal (non-Django) content, while http://django.satoshi.example.com/ would allow my Django content to be served. But currently any subdomain, whether satoshi.example.com or blahblahasdas.satoshi.example.com is serving my Django files (I know because I can go to the /admin page on both site, although they will be in different sessions).

反正这里是我这是运行 CentOS的服务器上的文件(不知道哪个版本),的Apache 2.2.15 的Python 2.6.6 Django的1.3.1 3.2的mod_wsgi

Anyway here are my files on the server which is running CentOS (not sure which version), Apache 2.2.15, Python 2.6.6, django 1.3.1, and mod_wsgi 3.2.

我将发布什么,我认为是最相关的文件和配置如下:

I will post what I think is the most relevant files and configuration below:

阿帕奇每次抛出这些错误我重新启动

Apache throws these errors everytime I restart

[Wed Feb 29 01:45:36 2012] [error] Exception KeyError: KeyError(140249420548064,) in <module 'threading' from '/usr/lib64/python2.6/threading.pyc'> ignored
[Wed Feb 29 01:45:36 2012] [error] Exception KeyError: KeyError(140249420548064,) in <module 'threading' from '/usr/lib64/python2.6/threading.pyc'> ignored
[Wed Feb 29 01:45:36 2012] [error] Exception KeyError: KeyError(140249420548064,) in <module 'threading' from '/usr/lib64/python2.6/threading.pyc'> ignored
[Wed Feb 29 01:45:36 2012] [error] Exception KeyError: KeyError(140249420548064,) in <module 'threading' from '/usr/lib64/python2.6/threading.pyc'> ignored
[Wed Feb 29 01:45:36 2012] [error] Exception KeyError: KeyError(140249420548064,) in <module 'threading' from '/usr/lib64/python2.6/threading.pyc'> ignored
[Wed Feb 29 01:45:36 2012] [error] Exception KeyError: KeyError(140249420548064,) in <module 'threading' from '/usr/lib64/python2.6/threading.pyc'> ignored
[Wed Feb 29 01:45:36 2012] [error] Exception KeyError: KeyError(140249420548064,) in <module 'threading' from '/usr/lib64/python2.6/threading.pyc'> ignored
[Wed Feb 29 01:45:36 2012] [error] Exception KeyError: KeyError(140249420548064,) in <module 'threading' from '/usr/lib64/python2.6/threading.pyc'> ignored
[Wed Feb 29 01:45:36 2012] [notice] SIGHUP received.  Attempting to restart
[Wed Feb 29 00:45:36 2012] [error] Exception KeyError: KeyError(140249420548064,) in <module 'threading' from '/usr/lib64/python2.6/threading.pyc'> ignored
[Wed Feb 29 01:45:36 2012] [notice] Digest: generating secret for digest authentication ...
[Wed Feb 29 01:45:36 2012] [notice] Digest: done
[Wed Feb 29 01:45:36 2012] [warn] mod_wsgi: Compiled for Python/2.6.2.
[Wed Feb 29 01:45:36 2012] [warn] mod_wsgi: Runtime using Python/2.6.6.
[Wed Feb 29 01:45:36 2012] [notice] Apache/2.2.15 (Unix) mod_auth_pgsql/2.0.3 PHP/5.3.3 mod_ssl/2.2.15 OpenSSL/1.0.0-fips mod_wsgi/3.2 Python/2.6.6 mod_perl/2.0.4 Perl/v5.10.1 configured -- resuming normal operations

下面是 /var/www/html/mysite/apache/apache_django_wsgi.conf 这将载入我的的httpd.conf 通过选项了NameVirtualHost *:80

Here is /var/www/html/mysite/apache/apache_django_wsgi.conf which gets loaded into my httpd.conf with the option NameVirtualHost *:80

<VirtualHost *:80>
    ServerName django.satoshi.example.com
    ErrorLog "/var/log/httpd/django_error_log"

    WSGIDaemonProcess django
    WSGIProcessGroup django

    Alias /media/ "/usr/lib/python2.6/site-packages/django/contrib/admin/media"
    <Directory "/usr/lib/python2.6/site-packages/django/contrib/admin/media">
        Order allow,deny
        Options Indexes
        Allow from all
        IndexOptions FancyIndexing
    </Directory>

    <Directory "/var/www/html/mysite">
        Order allow,deny
        Options Indexes
        Allow from all
        IndexOptions FancyIndexing
    </Directory>

    WSGIScriptAlias / "/var/www/html/mysite/apache/django.wsgi"

    <Directory "/var/www/html/mysite/apache">
        Order deny,allow
        Allow from all
    </Directory>
</VirtualHost>

下面是 /var/www/html/mysite/apache/django.wsgi

import os
import sys

paths = [
    '/var/www/html/mysite',
    '/var/www/html',
    '/usr/lib/python2.6/site-packages/',
]

for path in paths:
    if path not in sys.path:
        sys.path.append(path)

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

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

和终于在这里是 /var/www/html/mysite/settings.py

# Absolute filesystem path to the directory that will hold user-uploaded files. 
# Example: "/home/media/media.lawrence.com/media/"
MEDIA_ROOT = ''

# URL that handles the media served from MEDIA_ROOT. Make sure to use a
# trailing slash.
# Examples: "http://media.lawrence.com/media/", "http://example.com/media/"
MEDIA_URL = ''

# Absolute path to the directory static files should be collected to.
# Don't put anything in this directory yourself; store your static files
# in apps' "static/" subdirectories and in STATICFILES_DIRS.
# Example: "/home/media/media.lawrence.com/static/"
PROJECT_ROOT = os.path.normpath(os.path.dirname(__file__))
STATIC_ROOT = os.path.join(PROJECT_ROOT, 'static')

# URL prefix for static files.
# Example: "http://media.lawrence.com/static/"
STATIC_URL = '/static/'

# URL prefix for admin static files -- CSS, JavaScript and images.
# Make sure to use a trailing slash.
# Examples: "http://foo.com/static/admin/", "/static/admin/".
ADMIN_MEDIA_PREFIX = '/static/admin/'

# Additional locations of static files
STATICFILES_DIRS = ( 
    # Put strings here, like "/home/html/static" or "C:/www/django/static".
    # Always use forward slashes, even on Windows.
    # Don't forget to use absolute paths, not relative paths.
)

# List of finder classes that know how to find static files in
# various locations.
STATICFILES_FINDERS = ( 
    'django.contrib.staticfiles.finders.FileSystemFinder',
    'django.contrib.staticfiles.finders.AppDirectoriesFinder',
#   'django.contrib.staticfiles.finders.DefaultStorageFinder',
)

让我知道,如果你们需要的任何其他文件。在此先感谢!

Let me know if you guys need any other files. Thanks in advance!

推荐答案

我觉得你应该改变:

Alias /media/ "/usr/lib/python2.6/site-packages/django/contrib/admin/media"

Alias /static/admin/ "/usr/lib/python2.6/site-packages/django/contrib/admin/media"

由于您有:

ADMIN_MEDIA_PREFIX = '/static/admin/'

这篇关于阿帕奇不提供Django管理静态文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆