best practice including javascript in django template

后端 未结 2 1959
我寻月下人不归
我寻月下人不归 2021-01-12 19:51

Previously I used to do like this in a template


...


        
2条回答
  •  暗喜
    暗喜 (楼主)
    2021-01-12 20:36

    I know this question is 6 years old, and the answer is an exact answer for the question. But somehow this came up for me so high in my google search results, I thought I would post additional info here, to help people like me, looking for best practice. Use template inheritance, and blocks for content, css and javascript.

    Docs:

    https://docs.djangoproject.com/en/2.0/ref/templates/language/#template-inheritance

    and a stackoverflow example, showing how to add another js file to the original js block using block.super:

    how to organize JS files in Django?

提交回复
热议问题