2013-05-04 35 views
2

我是django的nooby,我嘗試了很多個小時來獲得dajaxice運行的簡單示例,但我似乎找不到找到這些文件的正確方法。如何導入dajaxice?

我做了並重新編寫了installation並試圖在許多類似的問題上找到答案,比如this onethis 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; 
+0

,請複製粘貼的'./manage.py collectstatic --noinput'輸出。 – 2013-05-04 21:00:21

+0

另外,檢查'settings.py'中是否有'DEBUG = True',啓動[firebug](https://addons.mozilla.org/en-US/firefox/addon/firebug/),打開'Console'標籤並重新加載您的頁面。您應該看到類似於Django錯誤頁面的信息,其中包含有關Firebug控制檯日誌中錯誤的詳細信息。 – 2013-05-04 21:11:48

+0

我編輯了我的原始問題,包括你要求的內容。 – kmgrds 2013-05-04 21:21:24

回答

2

看起來好像你已經搞砸了你的urls.conf。它應該包含如下內容:

url(dajaxice_config.dajaxice_url, include('dajaxice.urls')), 

是嗎?

此外,您settings.py文件的STATICFILES_FINDERS部分應包括:

'dajaxice.finders.DajaxiceFinder', 
+0

感謝您的快速回答!我的STATICFILES_FINDERS有第三行(DefaultStorageFinder)取消註釋,但我嘗試了兩種方法,但沒有什麼區別,我試過評論和取消註釋。任何其他想法我可以檢查? – kmgrds 2013-05-04 21:03:03

+0

嗨! @kmgrds,請粘貼'./manage.py collectstatic --noinput'的輸出。 – 2013-05-04 21:03:41

+0

太長的評論:希望這個尾巴夠用了: return self.nodelist.render(context) 文件「/usr/lib/python2.7/dist-packages/django/template/base.py」,第823行,渲染 bit = self.render_node(node,context) 文件「/usr/lib/python2.7/dist-packages/django/template/debug.py」,第74行,在render_node中 return node.render(上下文) 文件「/usr/lib/python2.7/dist-packages/django/template/defaulttags.py」,第424行,在渲染中 raise e django.core.urlresolvers.NoReverseMatch:對於'dajaxice-endpoint '找不到參數'()'和關鍵字參數'{}'。 – kmgrds 2013-05-04 21:09:03