-1

I am trying to use a static file in Django. I have set it us a below, but it doesn't find the file. This is on localhost.

In urls:

url(r'^static/(?P<path>.*)$', 'django.views.static.serve', {'document_root': settings.STATIC_ROOT}),

In settings:

STATIC_ROOT  = "C:/path/to/static/"
STATIC_URL = '/static/'

INSTALLED_APPS = (....'django.contrib.staticfiles', ...)

Copy-pasting the static root into explorer does go to the folder with the json2_min.js file

HTML:

<script src="/static/json2_min.js"></script>
user984003
  • 28,050
  • 64
  • 189
  • 285
  • Access the static files like this in your template `{{ STATIC_URL }}json2_min.js`. Also have you put `django.contrib.staticfiles` in your installed apps? Did you read: https://docs.djangoproject.com/en/dev/howto/static-files/ – Henrik Andersson May 25 '13 at 08:10
  • I do have django.contrib.staticfiles in my installed apps. {{ STATIC_URL }} just reads the static_url, which is "/static/", like I wrote in the script src. I did read the docs. That's how I started. – user984003 May 25 '13 at 08:16
  • You don't need the `urls.py` configuration. If you follow the tutorial or this post http://stackoverflow.com/questions/14799835/django-static-files-results-in-404/14800489#14800489 – Henrik Andersson May 25 '13 at 08:55
  • Still no dice. Removed the url configuration and moved the static_root path to staticfiles_dirs. The staticfiles_finders were already there. – user984003 May 25 '13 at 09:15

1 Answers1

0

Alright, I found two ways to solve this.

One, I REMOVED 'django.contrib.staticfiles' from INSTALLED_APPS.

or, two, I changed the word static:

in urls,

 url(r'^not_static/(?P<path>.*)$'.....

and correspondingly in the html:

<script src="/not_static/json2_min.js"></script>

I must have been trying to override some native static functionality. Seems there should be a third solution that actually makes the default static functionality work, but I din't find it.

user984003
  • 28,050
  • 64
  • 189
  • 285