[英]How to tell my django template where static file (dajax.core.js) is?
我正在嘗試在Django應用程序中使用Dajax ,但是當我嘗試將其包含在html模板中時出現404錯誤。 我已經在Windows 7上安裝了Dajax和Dajaxice。這是我的STATIC_URL的樣子:
STATIC_URL = '/static/'
我的靜態文件夾位於應用程序的文件夾中,因此在我的Eclipse項目中的src文件夾中,靜態文件夾的路徑為:
appname/static
我已將以下javascript文件放入靜態目錄中的“ js”目錄中:
dajaxice.core.js
jquery.dajax.core.js
我的模板的head標簽中是我的script標簽,如下所示:
<script src="{{ STATIC_URL }}js/jquery.dajax.core.js" type="text/javascript" charset="UTF-8"></script>
但是,當我打開模板時,出現以下錯誤:
GET http://localhost:8000/dajax/js/jquery.dajax.core.js 404 (NOT FOUND)
為什么找不到jquery.dajax.core.js? 謝謝你的幫助!
編輯此外,這就是我的觀點:
from django.shortcuts import render_to_response
from django.template import RequestContext
def dajax(request):
return render_to_response('dajax.html', context_instance=RequestContext(request))
這很簡單,因為我只是測試一下。
我認為這是因為您需要為django添加靜態服務器(僅用於本地運行)
將此添加到您的urls.py:
if settings.DEBUG:
urlpatterns += patterns('',
(r'^static/(.*)$', 'django.views.static.serve', {'document_root': settings.STATIC_PATH}),
)
或者您需要將MEDIA_ROOT
指向靜態文件夾的絕對路徑。
否則,我想您會在設置中聲明兩次STATIC_URL
,因為您說已將其設置為/static/
,但是模板似乎將其替換為dajax
即GET http://localhost:8000/dajax/js/jquery.dajax.core.js 404 (NOT FOUND)
應該是http://localhost:8000/static/js/jquery.dajax.core.js
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.