title: How to get django static files in app directory?
body: <p>I have some doubts about accessing django's static files.</p>
  
  <p>VERSION: 1.8.4<br>
  VARs in settings.py:</p>
  
  <pre><code>BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
  STATIC_ROOT = join(PROJECT_ROOT, 'static')
  STATIC_URL = '/static/'STATICFILES_DIRS = (
      os.path.join(BASE_DIR, "static"),
  )
  
  
  TEMPLATES = [
      {
          'BACKEND': 'django.template.backends.django.DjangoTemplates',
          'DIRS': [
              # insert your TEMPLATE_DIRS here
              # os.path.join(BASE_DIR, 'templates').replace('\\', '/')
          ],
          'APP_DIRS': True,
          'OPTIONS': {
              'context_processors': [
                  # Insert your TEMPLATE_CONTEXT_PROCESSORS here or use this
                  # list if you haven't customized them:
                  'django.contrib.auth.context_processors.auth',
                  'django.template.context_processors.debug',
                  'django.template.context_processors.i18n',
                  'django.template.context_processors.media',
                  'django.template.context_processors.static',
                  'django.template.context_processors.tz',
                  'django.contrib.messages.context_processors.messages',
              ],
          },
      },
  ]
  </code></pre>
  
  <ol>
  <li><p>setting STATICFILES_DIRS, and adding <code>django.template.context_processors.static</code> to context_processors in <code>TEMPLATES</code>, so I can use 'static' tag in template. A src tag like: <code>src="{{STATIC_URL}}js/example.js"</code> or <code>src="{% static 'js/example.js' %}"</code> will generate a url to <code>http://myhost/static/js/example.js</code>.</p></li>
  <li><p>If I want load static files in app directory, what should I do? As my understanding of django-official-doc,<br>
  <code>STATICFILES_FINDERS = (
  'django.contrib.staticfiles.finders.AppDirectoriesFinder',
  'django.contrib.staticfiles.finders.FileSystemFinder',
  )</code><br>
  the finders will search <code>app/static</code> in default, but if a <code>src="static/js/example.js"</code> in <code>app/templates/index.html</code>, the server will return a 404 code. Until I add <code>urlpatterns += staticfiles_urlpatterns()</code> to <code>app/urls.py</code>.</p></li>
  </ol>
  
  <p>What i want to know is:</p>
  
  <ol>
  <li><p>Why 404? When load static file form <code>app/static</code> without <code>urlpatterns += staticfiles_urlpatterns()</code>.</p></li>
  <li><p>If I want to get static file in <code>app/static</code>, how to write url in a flexible way? cause <code>{{STATIC_URL}}</code> or <code>{% static %}</code> both point to project/static.</p></li>
  </ol>
  
  <p>I have spend hours in reading related post on stackoverflow. Any help would be sooo greatly appreciated.</p>