将jQuery加载到Django [英] Load jQuery into Django
问题描述
我下载了 jQuery 并把它放在我认为是我的Media文件夹中。我的settings.py文件如下所示:
MEDIA_ROOT = os.path.join(PROJECT_DIR,'books / media /') <峰; br>
MEDIA_URL ='http:// localhost:8000 / books / media /'
我的html模板,我参考:
< script type =text / javascriptsrc =/ media / js /jquery-1.4.2.min.js\">
但是我的功能都没有工作。我相信这是一个愚蠢和显而易见的事情(虽然对我来说显然不是很明显)。如何正确地导入jQuery?
您可以将链接硬编码为
< script type =text / javascriptsrc =/ books / media / js / jquery-1.4.2.min.js>
或者如果您使用 RequestContext
并使用 django.core.context_processors.media
上下文处理器,那么您可以在模板中访问 MEDIA_URL
/ p>
< script type =text / javascriptsrc ={{MEDIA_URL}}} js / jquery-1.4.2。 min.js>
I have a really basic question. I'm trying to build some AJAX functionality into a Django project. I plan to use jQuery. Right now, I'm just running the code locally through Linux. I've been testing some code here so I'm reasonably certain that it works. But I'm having trouble figuring where to put the jQuery source code in combination with my settings.
I downloaded jQuery and put it in what I think is my Media folder. My settings.py file reads as follows:
MEDIA_ROOT = os.path.join(PROJECT_DIR, 'books/media/')<br>
MEDIA_URL = 'http://localhost:8000/books/media/'
In my html template, I'm referencing:
<script type="text/javascript" src="/media/js/jquery-1.4.2.min.js">
But none of my functions are working. I'm sure it's something stupid and obvious (though clearly not obvious to me). How do I correctly source jQuery?
You can hardcode the link as
<script type="text/javascript" src="/books/media/js/jquery-1.4.2.min.js">
or if you render your template with a RequestContext
and use the django.core.context_processors.media
context processor, then you can access MEDIA_URL
in your template.
<script type="text/javascript" src="{{ MEDIA_URL }}}js/jquery-1.4.2.min.js">
这篇关于将jQuery加载到Django的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!