2015-09-04 42 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', 

    # ... 
)