2013-07-15 23 views
0

進口在HTML模塊:沒有名爲 'Dajaxice'

<script src="/media/js/jquery-2.0.2.js"></script> 
<script src="jquery.dajax.core.js"></script> 

<script type="text/javascript"> 
function oneri() 
{ 
    Dajaxice.rezervationApp.oneri(Dajax.process) 
} 
</script> 

我用:

在ajax.py

from django.template.loader import render_to_string 
from dajaxice.decorators import dajaxice_register 
from django.shortcuts import render 
from rezervationApp.models import RoomType, Room, Market, Profile, Reservation 


@dajaxice_register 
def oneri(request, word): 
    dajax = Dajax() 
    p = Profile.objects.get(firstname__contains=word) 
    dajax.assign('#advice','innerHTML', p) 
    return dajax.json() 

完全錯誤

<div class="span6"> <a href="#adviceModal" class="btn" role="button" onClick="oneri()" data-toggle="modal">Öneri Al</a></div> 

ImportError at/
No module named 'Dajaxice' 
Request Method: GET 
Request URL: http://127.0.0.1:8000/ 
Django Version: 1.5.1 
Exception Type: ImportError 
Exception Value:  
No module named 'Dajaxice' 
Exception Location: C:\Python33\lib\site-packages\dajaxice\core\__init__.py in <module>, line 3 

但是,總是相同的錯誤。 我將其他文件配置爲dajax教程。 你有什麼想法嗎?

回答

1

如果我沒有記錯的Dajaxice教程離開了,你居然要安裝Dajaxice部分...

如果你還沒有,你應該嘗試pip install django-dajaxice

3

的問題是在PY2之間的差異和py3。 Py3允許只顯式相對導入。 它在你添加一個點時起作用。

from .Dajaxice import Dajaxice, dajaxice_autodiscover 
+0

我的應用程序託管在heroku上,有沒有辦法修改__init__.py?或者還有其他解決方法嗎? –

-1

如果這是您生成的HTML,那麼問題出在哪裏。如果您按照Dajaxice的文檔設置了教程,則可能在模板的頭部使用了{% load dajaxice_templatetags %} {% dajaxice_js_import %}。這應該會生成靜態文件夾所在的靜態dajaxice.core.js文件,並在您生成的HTML中向您顯示類似<script charset="utf-8" type="text/javascript" src="/static/dajaxice/dajaxice.core.js">的內容。

如果您完全按照Dasjax和Dajaxice的安裝步驟進行操作,請將settings.py中的STATIC_ROOT設置定義爲靜態根文件夾的位置(相對於settings.py文件),然後運行python manage.py collectstatic爲Dajaxice JavaScript文件提供200個最終304響應,並且您的應用應該運行得很好。