Note that there are some explanatory texts on larger screens.

plurals
  1. PODjango static files won't load
    primarykey
    data
    text
    <p>i'm a Django newbie working on my first project and having a problem with static files.</p> <p>I have created a simple auth system using <code>django.contrib.auth</code> consisting of two templates: <code>mysite/templates/index.html</code> and <code>mysite/templates/registration/login.html</code>. I have global static content in <code>mysite/static</code> which I want to be able to access on all templates rendered by all apps.</p> <p><code>mysite/templates/index.html</code> contains <code>&lt;img src="{{ STATIC_URL }}pics03.jpg"/&gt;</code> which renders as <code>"static/pics03.jpg"</code> and loads fine when I visit the url <code>localhost:8000/</code></p> <p><code>mysite/templates/registration/login.html</code> contains <code>&lt;img src="{{ STATIC_URL }}pics03.jpg"/&gt;</code> which also renders as <code>"static/pics03.jpg"</code> and does not load when I visit the url <code>"localhost:8000/accounts/login/"</code></p> <p>In my urls.py I have:</p> <pre><code>urlpatterns = patterns('', url(r'^$', 'mysite.views.home'), # plays index.html template url(r'^accounts/login/$', 'django.contrib.auth.views.login'), </code></pre> <p>In my settings.py I have:</p> <pre><code>PROJECT_DIR = os.path.dirname(__file__) 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. os.path.join(PROJECT_DIR,'static'), ) STATICFILES_FINDERS = ( 'django.contrib.staticfiles.finders.FileSystemFinder', 'django.contrib.staticfiles.finders.AppDirectoriesFinder', ) STATIC_URL = '/static/' STATIC_ROOT = '' </code></pre> <p>I was under the impression that Django should be looking for global static content in STATICFILES_DIRS, but it doesn't find the static content for login.html even if I change the url in there to an absolute path to the static folder. Can anyone shed any light on this?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    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