Note that there are some explanatory texts on larger screens.

plurals
  1. POApache not serving django admin static files
    primarykey
    data
    text
    <p>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!</p> <p>So I know there are many similar questions about this and I have read a <a href="https://stackoverflow.com/questions/1179453/django-and-serving-static-files">bunch</a> <a href="https://stackoverflow.com/questions/3043868/problem-with-django-styling">of</a> <a href="https://stackoverflow.com/questions/6402185/serving-static-files-while-running-djangomod-wsgi-on-apache-2-2">questions</a> <a href="https://stackoverflow.com/questions/3271731/djangos-admin-pages-are-missing-their-typical-formatting-style-have-i-set-it-u">about</a> <a href="https://stackoverflow.com/questions/6014663/django-static-file-not-found">serving</a> <a href="https://stackoverflow.com/questions/6073916/problems-linking-to-static-files-in-django-1-3">static</a> <a href="https://stackoverflow.com/questions/5396552/problem-applying-css-in-django-with-static-files-app">media</a> <a href="https://stackoverflow.com/questions/6409920/django-static-files-from-app-directories">files</a> <a href="https://stackoverflow.com/questions/1833675/django-admin-has-no-style">on</a> <a href="https://stackoverflow.com/questions/5687136/static-media-fails-to-load-in-django">Django</a>.</p> <p>I read about <code>STATIC_URL</code>, <code>STATIC_ROOT</code>, the (soon to be obsolete) <code>ADMIN_MEDIA_PREFIX</code>, and setting a <code>Alias /media/ ...</code> in the Apache configuration. I tried to test out each solution one by one, but I couldn't get anything working.</p> <p>Here is what my admin site looks like right now</p> <p><img src="https://i.imgur.com/vBLMQ.png" /></p> <p>I'm also having a weird case where <strong><em>any</em></strong> subdomain works on my server. For example I was trying to set up my server so that <a href="http://www.satoshi.example.com/" rel="nofollow noreferrer">http://www.satoshi.example.com/</a> would allow my normal (non-Django) content, while <a href="http://django.satoshi.example.com/" rel="nofollow noreferrer">http://django.satoshi.example.com/</a> 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 <code>/admin</code> page on both site, although they will be in different sessions).</p> <p>Anyway here are my files on the server which is running <code>CentOS</code> (not sure which version), <code>Apache 2.2.15</code>, <code>Python 2.6.6</code>, <code>django 1.3.1</code>, and <code>mod_wsgi 3.2</code>.</p> <p>I will post what I think is the most relevant files and configuration below:</p> <p>Apache throws these errors everytime I restart</p> <pre><code>[Wed Feb 29 01:45:36 2012] [error] Exception KeyError: KeyError(140249420548064,) in &lt;module 'threading' from '/usr/lib64/python2.6/threading.pyc'&gt; ignored [Wed Feb 29 01:45:36 2012] [error] Exception KeyError: KeyError(140249420548064,) in &lt;module 'threading' from '/usr/lib64/python2.6/threading.pyc'&gt; ignored [Wed Feb 29 01:45:36 2012] [error] Exception KeyError: KeyError(140249420548064,) in &lt;module 'threading' from '/usr/lib64/python2.6/threading.pyc'&gt; ignored [Wed Feb 29 01:45:36 2012] [error] Exception KeyError: KeyError(140249420548064,) in &lt;module 'threading' from '/usr/lib64/python2.6/threading.pyc'&gt; ignored [Wed Feb 29 01:45:36 2012] [error] Exception KeyError: KeyError(140249420548064,) in &lt;module 'threading' from '/usr/lib64/python2.6/threading.pyc'&gt; ignored [Wed Feb 29 01:45:36 2012] [error] Exception KeyError: KeyError(140249420548064,) in &lt;module 'threading' from '/usr/lib64/python2.6/threading.pyc'&gt; ignored [Wed Feb 29 01:45:36 2012] [error] Exception KeyError: KeyError(140249420548064,) in &lt;module 'threading' from '/usr/lib64/python2.6/threading.pyc'&gt; ignored [Wed Feb 29 01:45:36 2012] [error] Exception KeyError: KeyError(140249420548064,) in &lt;module 'threading' from '/usr/lib64/python2.6/threading.pyc'&gt; 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 &lt;module 'threading' from '/usr/lib64/python2.6/threading.pyc'&gt; 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 </code></pre> <p>Here is <code>/var/www/html/mysite/apache/apache_django_wsgi.conf</code> which gets loaded into my <code>httpd.conf</code> with the option <code>NameVirtualHost *:80</code></p> <pre><code>&lt;VirtualHost *:80&gt; 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" &lt;Directory "/usr/lib/python2.6/site-packages/django/contrib/admin/media"&gt; Order allow,deny Options Indexes Allow from all IndexOptions FancyIndexing &lt;/Directory&gt; &lt;Directory "/var/www/html/mysite"&gt; Order allow,deny Options Indexes Allow from all IndexOptions FancyIndexing &lt;/Directory&gt; WSGIScriptAlias / "/var/www/html/mysite/apache/django.wsgi" &lt;Directory "/var/www/html/mysite/apache"&gt; Order deny,allow Allow from all &lt;/Directory&gt; &lt;/VirtualHost&gt; </code></pre> <p>Here is <code>/var/www/html/mysite/apache/django.wsgi</code></p> <pre><code>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() </code></pre> <p>And finally here is part of <code>/var/www/html/mysite/settings.py</code></p> <pre><code># 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', ) </code></pre> <p>Let me know if you guys need any other files. Thanks in advance!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload