2015-09-04 44 views
0

沿hereDjango的靜態jQuery的PIP安裝不會加載

我成功運行之後:

pip install django-static-jquery==2.1.4 

但是,我不能去在Django正確送達的靜態內容。我有一個簡單的html頁面:

<html> 
    {% load staticfiles %} 
    {% static 'static_jquery/js/jquery.js' %} 
</html> 

每個網頁。所有最終發生的是我的HTML只是吐出這個:

/static/static_jquery/js/jquery.js 

而不是實際加載庫。我正在使用默認的Django推出,所以我很好奇它在這個過程中缺少的是什麼。

settings.py:

INSTALLED_APPS = (... 
     django_static_jquery, 
) 

僅包括 'jQuery的' 作爲在其他問題提出不工作。

+0

@ J0HN是的。很快會更新我的問題。 – Woot4Moo

回答

5

實際上,{% static %}只是輸出一個URL。如果你想加載的JavaScript文件,只是這樣做:

<html> 
    <head> 
     <script type="text/javascript" src="{% static 'static_jquery/js/jquery.js' %}"></script> 
    </head> 
</html> 
+0

這現在結果200謝謝你!我還不能接受這個答案。但是,這是否也可以在非調試模式下工作?即生產 – Woot4Moo

+0

是的,但在生產中您需要['collecstatic'](https://docs.djangoproject.com/en/1.8/ref/contrib/staticfiles/#django-admin-collectstatic)。 –

+0

似乎現在有一個小問題,當我做一個簡單的hello世界時,jquery不能找到id。這聽起來像你經歷過的事情嗎? – Woot4Moo

2

您是否已將此添加到安裝的應用程序?

INSTALLED_APPS = (
    # ... 

    'django.contrib.staticfiles', 
    'django_static_jquery', 

    # ... 
)