如何使STATIC_URL在外部JS文件(Django)中工作 [英] How to make STATIC_URL work in external JS Files (Django)
问题描述
我正试图在外部的javascript文件中使用STATIC_URL。我正在期待结果,因为它在模板中工作,但我发现它不在外部Javascript文件中。
I am trying to use STATIC_URL in external javascript file. I was expecting the result as it is working in template, but I found that it is not working in external Javascript file.
请告诉我一些工作,使STATIC_URL工作在javascript文件,因为它会使我的项目更易于管理。
Please also tell me some work around to make STATIC_URL work in javascript file as it will make my project more manageable.
另外我发送了很多ajax请求,我想在我的JS文件中有一些像url模板标签。
Also I am sending many ajax request and i want to have something like url template tag in my JS file.
如果您知道任何一个解决方案,请通知我。
Please let me know if you know solution of any of them.
谢谢
推荐答案
我使用一个简单的Django应用程序,使Python / Django设置在javascript中可用。
I use a simple Django app for making Python / Django settings available in javascript.
https://github.com/incuna/ django-settingsjs
它以相同的方式通过渲染模板中的设置,但提供了一种使用视图在JavaScript中使多个变量可用的机制,网址和可选信号。
It works in the same way by rendering the settings in a template but provides a mechanism for making multiple variables available in JavaScript using a view, urls and optionally signals.
这篇关于如何使STATIC_URL在外部JS文件(Django)中工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!