我是django的nooby,我嘗試了很多個小時來獲得dajaxice運行的簡單示例,但我似乎找不到找到這些文件的正確方法。如何導入dajaxice?
我做了並重新編寫了installation並試圖在許多類似的問題上找到答案,比如this one和this one。
我把{% dajaxice_js_import %}
在myapp_index.html
它打印出來作爲標題:
<script src="/static/dajaxice/dajaxice.core.js"
type="text/javascript" charset="utf-8"></script>
但它無法找到該文件:
ImproperlyConfigured:在staticfiles取景器的存儲後端沒有一個有效的位置。
的GET失敗:
GET /static/dajaxice/dajaxice.core.js HTTP/1.1" 500 59
奇怪的是dajax負載:
<script type="text/javascript"
src="{% static /static/dajax/jquery.dajax.core.js" %}"></script>
這裏是我的文件夾結構:
myproject
----manage.py
----myproject
--------settings.py
--------urls.py
----myapp
--------ajax.py
--------urls.py
--------templates
------------myapp_index.html
我還沒有真正理解爲什麼我們需要兩個urls.py
文件,但不知何故它似乎訪問myapp_index.html
如果我把
from django.views.generic.simple import direct_to_template
然後
url(r'^$', direct_to_template, {'template': 'myapp_index.html'}),
在myapp
的URL模式。
我也嘗試過無數的文件名中
python manage.py findstatic dajaxice.core.js
但不知何故沒有找到dajaxice,即使dajaxice已安裝並在INSTALLED_APPS
中settings.py文件接受。
另外python manage.py collectstatic
由於同樣的原因失敗,但如果我理解正確,我不會讓事件發生,只要我在開發服務器上。
我想我對底層結構有一些基本的誤解。 :(
我使用的是預裝最新的Ubuntu軟件包:
django: 1.4.5,
dajaxice: 0.5.5
預先感謝任何提示!
這裏的模板文件:
{% load static %}
{% load dajaxice_templatetags %}
<html>
<head>
<title>My base template</title>
{% dajaxice_js_import %}
<script type="text/javascript" src="{% static "/static/dajax/jquery.dajax.core.js" %}"></script>
<script type="text/javascript">
function my_js_callback(data){
alert(data.message);
}
Dajax;
Dajaxice;
</script>
</head>
...
<button onclick="Dajaxice.myproject.myapp.sayhello(my_js_callback);">Click here!</button>
我沒有得到任何Django的錯誤,頁面顯示,但我得到這個在Firebug:
"NetworkError: 500 Internal Server Error - http://localhost:8000/static/dajaxice/dajaxice.core.js"
這:
ReferenceError: Dajaxice is not defined
Dajaxice;
,請複製粘貼的'./manage.py collectstatic --noinput'輸出。 – 2013-05-04 21:00:21
另外,檢查'settings.py'中是否有'DEBUG = True',啓動[firebug](https://addons.mozilla.org/en-US/firefox/addon/firebug/),打開'Console'標籤並重新加載您的頁面。您應該看到類似於Django錯誤頁面的信息,其中包含有關Firebug控制檯日誌中錯誤的詳細信息。 – 2013-05-04 21:11:48
我編輯了我的原始問題,包括你要求的內容。 – kmgrds 2013-05-04 21:21:24