1 回答

TA貢獻(xiàn)1796條經(jīng)驗(yàn) 獲得超7個(gè)贊
我在Django框架中這樣做了,如下所示:索引.html
{% if load_minified_scripts %}
<script src="{% static "minified_assets/js/site.min.js" %}"></script>
{% else %}
<script src="{% static "script/app.js" %}"></script>
<script src="{% static "script/controller.js" %}"></script>
{% endif %}
這是從服務(wù)器端設(shè)置的。load_minified_scripts
views.py
@csrf_protect
@requires_csrf_token
def index(request):
if request.session.session_key is None:
request.session['has_session'] = True
request.session.modified = True
return render(request, 'index.html', {'user': request.user,
'debug': settings.DEBUG,
'session_key': request.session.session_key,
"load_minified_scripts": settings.LOAD_MINIFIED_SCRIPTS}
, content_type="text/html")
根據(jù) ,得到它的值。對(duì)于環(huán)境來(lái)說(shuō),它是。envsettings.LOAD_MINIFIED_SCRIPTSDEVfalse
同樣,您也可以為其他語(yǔ)言執(zhí)行此操作。
添加回答
舉報(bào)