2

I'm trying to reorganize my project, as the files in it are very unorganized. There is a static folder in the main project folder that should only have all of the apps. So I'm relocating some of the .js files into their respective apps.

One of the files is in /static/js/mmm and I'm trying to move it to mmm/static/mmm. I copied the file over and changed the code in one of my templates (located in mmm/templates/mmm) from

<script src="/static/js/mmm/filemanage.js" type="text/javascript"></script>

to

{% load staticfiles %}
<script src="{% static "mmm/filemanage.js" %}" type="text/javascript"></script>

However I opened the page and the js console and it is trying to access the file like this:
http://fakedomain.com/static/mmm/filemanage.js

From my understanding it should be looking in http://fakedomain.com/mmm/static/mmm/filemanage.js

In my settings file I have 'mmm' as an installed app and

STATIC_ROOT = os.path.join(BASE_DIR, 'static')

STATICFILES_DIRS = (
    os.path.join(BASE_DIR, 'assets'),
)

STATIC_URL = '/static/'

Not sure what I'm doing wrong here as I don't totally understand how Django searches for the static files. I also didn't put those things in the settings files so I don't understand what they're doing. The Django tutorial, part 6 says that "Django’s STATICFILES_FINDERS setting contains a list of finders that know how to discover static files from various sources. One of the defaults is AppDirectoriesFinder which looks for a “static” subdirectory in each of the INSTALLED_APPS, like the one in polls we just created. "

skullkid
  • 448
  • 4
  • 13
  • I's looking in the correct folder. You defined it with STATIC_URL. So STATIC_URL + static/parcelManage.js = /static/static/parcelManage.js – FrEaKmAn May 28 '14 at 14:39

1 Answers1

1

I believe your problem is with this line:

<script src="{% static "static/parcelManage.js" %}" type="text/javascript"></script>

Reveiw the documentation for static files here.

Basically, it looks like you should change the line to:

<script src="{% static "measuring/parcelManage.js" %}" type="text/javascript"></script>

Mike
  • 2,514
  • 2
  • 23
  • 37
  • 1
    I was reading this documentation "https://docs.djangoproject.com/en/1.6/intro/tutorial06/" and it says to create a folder for the app name within the static folder within the measuring folder. so it would be in measuring/static/measuring. Maybe i should put it in measuring/static/measuring/js – skullkid May 28 '14 at 15:37
  • 1
    I changed it to "measuring/parcelManage.js" and now it is looking for it in http://fakedomain.com/static/measuring/parcelManage.js. – skullkid May 28 '14 at 15:40
  • maybe something in your settings file is messed up. In the Django project I'm working on, I use an linux absolute path for my `STATIC_ROOT` (i.e. /opt/myapp/static/) – Mike May 28 '14 at 17:25