可能重複:
Trying to serve django static files on development server - not found的Django 1.4靜態文件未找到錯誤
我剛剛進入Python和Django的世界,我無法使用STATIC_URL設置我的網址,我我目前正在使用django 1.4進行本地開發。我閱讀django static file doc並似乎添加了所有需要的內容,但仍然出現404錯誤。我已經閱讀了與此相關的其他Q & A,並嘗試了各種各樣的東西,但無法使其工作。
錯誤我從控制檯
http://localhost:8000/blog/static/js/src/models/myfile.js 404 (NOT FOUND)
我的index.html頁面,這是我的主要頁面,其他頁面擴展得到了下面的腳本:
<script src="{{ STATIC_URL }}/js/src/models/myfile.js"></script>
通過其他去後問題和答案所以我試圖通過添加編輯我的看法,因爲我的archive.html是渲染數據:
from django.template import RequestContext
...
return render_to_response('archive.html', {'categories' : resultSet, 'data': queryData}, context_instance=RequestContext(request))
我的目錄結構 -
mysite
|-- manage.py
|-- mysite
|-- __init__.py
|-- settings.py
|-- urls.py
|-- wsgi.py
|-- blog
|-- __init__.py
|-- models.py
|-- tests.py
|-- views.py
|-- temapltes
|-- archive.html
|-- base.html
|-- static
|-- js
|-- myfile.js
我Settings.py
MEDIA_ROOT = ''
MEDIA_URL = ''
STATIC_ROOT = ''
STATIC_URL = '/static/'
STATICFILES_DIRS = (
'C:/Python27/Scripts/mysite/blog/static',
# A Bit confused on the path here
)
STATICFILES_FINDERS = (
'django.contrib.staticfiles.finders.FileSystemFinder',
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
)
TEMPLATE_CONTEXT_PROCESSORS = (
"django.core.context_processors.auth",
"django.core.context_processors.debug",
"django.core.context_processors.i18n",
"django.core.context_processors.media",
'django.core.context_processors.static',
)
TEMPLATE_DIRS = ()
INSTALLED_APPS = (
#..
'django.contrib.staticfiles',
'blog',
)
我想我有多數民衆贊成所需的一切,但仍與它沒有運氣。
我在哪裏出了問題,我是在設置「STATICFILES_DIRS」路徑有點糊塗了,我怎麼能得到這個工作我的本地機器上
擴展設置示例:http://stackoverflow.com/questions/11033571/using-static-files-with-the-django-virtual-server/11033706#11 033706 –
http://stackoverflow.com/questions/9197599/how-to-serve-static-files-in-django-development-server – supervacuo
http://stackoverflow.com/questions/12026010/trying-to-serve- django-static-files-on-development-server-not-found/12029220 – supervacuo