简体   繁体   中英

django - 404 not found error when loading static files

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.

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

您的STATIC_URL需要以斜杠开头。

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 :)

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM