Using a Django variable in a CSS file

后端 未结 2 1863
故里飘歌
故里飘歌 2020-12-08 11:24

I am trying to create a dynamic CSS file using the Django templating engine or any other means.

Currently, I have a CSS rule that looks like this:



        
2条回答
  •  囚心锁ツ
    2020-12-08 12:03

    You basically have two options:

    1. Serve your CSS dynamically, with an entry in urls.py, etc., just as if it were an HTML page. Your template file will simply be CSS instead of HTML, but will use normal Django template syntax, etc.

    2. Shortcut: Reference your background image with a relative path. This may or may not be possible for your environment, but it's a convenient way of having a static CSS file reference different paths depending on where it's hosted.

提交回复
热议问题