4

I read the https://docs.djangoproject.com/en/dev/howto/static-files/ multiple times and I'm pulling my hairs out. I can't load my .js and .css files. Chrome debugger keeps getting me a "404 not found" for .js and .css files. This is what is in debugger:

http://127.0.0.1:8000/meetingapp/static/css/jquery-ui-1.8.14.custom.css 404 (NOT FOUND)

This is how I call css file in my base.html template:

<link type="text/css" href="{{ STATIC_URL }}css/jquery-ui-1.8.14.custom.css" rel="stylesheet" />

I'm running a developer server:

python manage.py runserver

settings.py

STATIC_URL = 'static/'
STATICFILES_FINDERS = (
'django.contrib.staticfiles.finders.FileSystemFinder',
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
#'django.contrib.staticfiles.finders.DefaultStorageFinder',
)
INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles'
)

urls.py

urlpatterns = patterns('meetingapp.views',
(r'^meetingapp/$', 'index'),
(r'^meetingapp/calc_meetings/$', 'calc_meetings')
)

Please help me. Thanks.

h3ndr1ks
  • 517
  • 2
  • 7
  • 18
  • 1
    It would help others reading this to specify a Django version? I'm guessing 1.3? – James Khoury Jul 27 '11 at 06:51
  • I was having the same problem, until I put an Alias for /static *before* the WSGI* directives in my apache config. Doesn't change the mapping of the files in my case, but *did* change the priority to make apache look in the static folder before handing off to Django. – Azendale Nov 05 '15 at 06:26

4 Answers4

4
http://127.0.0.1:8000/meetingapp/static/css/jquery-ui-1.8.14.custom.css 404 (NOT FOUND)
                      ^^^^^^^^^^^ Your problem is right here...

You see that static is usually situated in the root of your project and it tries to find in your app root. And you need to chage your main settings.py STATIC FILES setting like so:

STATIC_URL = '/static/'
             ^ add a slash here

So your Static url will be:

http://127.0.0.1:8000/static/css/jquery-ui-1.8.14.custom.css
garmoncheg
  • 867
  • 11
  • 26
3

I just figured it out: I had to add a record to STATICFILES_DIRS in settings.py

STATICFILES_DIRS = (
"/Projects/MeetingOrganization/meetings/meetingapp/static",
)

Thanks anyway :)

h3ndr1ks
  • 517
  • 2
  • 7
  • 18
  • 2
    This is the wrong solution. If this worked for you it was because you short circuited a number of other things that you shouldn't have had to. The other suggestions here are correct - although I suspect that your problem is caused by something else. I am currently struggling with this same problem for 1.42, and I spent about 30 minutes trying out your suggestion until I understood that it was entirely wrong. – kamelkev Jul 15 '13 at 02:14
  • i think the problem here is that if the answer works, its not the wrong answer. the worst answer is no answer at all. – Michael Lorenzo Jul 21 '14 at 23:30
  • This is actually correct. Often, ```STATICFILES_DIRS``` is commented out during deployment. Not commenting that part seems to be useful for localhost, though. – Dimanjan Feb 17 '20 at 08:03
2

Your STATIC_URL needs to begin with a slash.

Daniel Roseman
  • 588,541
  • 66
  • 880
  • 895
1

I have spent whole day, solving the same problem in my project.

the problem was in not ASCII keys in Windows register (regedit) in HKEY_CLASSES_ROOT\MIME\Database\Content Type find out the non-ASCII keys (such as šßü) and delete them.

hope it will help

Slava
  • 133
  • 2
  • 8