简体   繁体   English

django - 加载静态文件时404未找到错误

[英]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. 我多次阅读https://docs.djangoproject.com/en/dev/howto/static-files/ ,我正在拔毛。 I can't load my .js and .css files. 我无法加载我的.js和.css文件。 Chrome debugger keeps getting me a "404 not found" for .js and .css files. Chrome调试器不断让我找到.js和.css文件的“404 not found”。 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: 这就是我在base.html模板中调用css文件的方法:

<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 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 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: 你需要使用这样的主设置.py静态文件设置:

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 我只是想通了:我必须在settings.py中为STATICFILES_DIRS添加一条记录

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. 问题是在HKEY_CLASSES_ROOT\\MIME\\Database\\Content Type中的Windows寄存器(regedit)中没有ASCII键找出非ASCII密钥(例如šßü)并删除它们。

hope it will help 希望它会有所帮助

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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