当前位置: 动力学知识库 > 问答 > 编程问答 >

Django: Template Tags and Javascripts Scripts to match

问题描述:

HI,

I am writing a bunch of template tags for a Django application, that need a certain javascript library.

Each of those template tags could exist multiple times on the same Template.

I was wondering if there is a smart way that I could add the Javscript library in the templatetag templates?

Here is an example TemplateTagA uses customA.js and TemplateTagB uses customB.js.

If I was to say put a extra javascript block tag with {{block.super}} (to not overwrite any other js's added), and TemplateTageA was used 3 times, customA.js would be added 3 times.

So that is not an ideal solution.

I could define in my Base Template a block tag for each script, but that would not be maintainable.

Any other ideas?

I have some more exotic ideas, like pull Javascripts source urls in an array, and then filter before downloading each one via Ajax.

However I am not sure if there are better approaches?

Looking forward to your responses...

网友答案:

I am trying to understand: your template tag values will be javascript blocks? Or are your template values being set in the view?

分享给朋友:
您可能感兴趣的文章:
随机阅读: