Note that there are some explanatory texts on larger screens.

plurals
  1. POSTATIC_URL undefined in base Django template
    primarykey
    data
    text
    <p>I have a template, <code>base.html</code>, which is used in several other templates for various views. Each of those templates starts with the appropriate <code>{% extends "base.html" %}</code>. In the base template, I want to specify a static stylesheet thusly:</p> <pre><code>&lt;link rel="stylesheet" type="text/css" href="{{ STATIC_URL }}/base.css"/&gt; </code></pre> <p>However, when it renders most of my templates, the value of <code>STATIC_URL</code> is empty, so the attribute is merely <code>href="/base.css"</code>, which doesn't load. The variable is properly defined for the template that I have tied to the default login view, <code>django.contrib.auth.views.login</code>, but for my own custom views, it's undefined.</p> <p>I am just trying to get this working in the development environment with <code>runserver</code>, so the CSS file is in the static subdirectory of the app.</p> <p>Here are the relevant bits from my <code>settings.py</code>, which are all the defaults:</p> <pre><code># URL prefix for static files. # Example: "http://media.lawrence.com/static/" STATIC_URL = '/static/' # 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', ) TEMPLATE_CONTEXT_PROCESSORS = ( 'django.core.context_processors.debug', 'django.core.context_processors.i18n', 'django.core.context_processors.media', 'django.core.context_processors.static', 'django.contrib.auth.context_processors.auth', 'django.contrib.messages.context_processors.messages', ) </code></pre> <p>In my <code>urls.py</code> I also have added:</p> <pre><code>from django.contrib.staticfiles.urls import staticfiles_urlpatterns #... urlpatterns += staticfiles_urlpatterns() </code></pre> <p>Any ideas what I'm doing wrong? As far as I can tell this is what you're supposed to do for serving app-specific static files in development, based on <a href="https://docs.djangoproject.com/en/1.3/howto/static-files/" rel="noreferrer">the 1.3 documentation</a>.</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.
    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