开发者

Django css files

i want to create some css styles for my Django templates. Each view will have a css associated, but there will be zones that are not associated to any views in my template.

How can i load the css files? is there enough having them declared in the Media of my view, and loading them in the header of the html?

Also, is it a correct approach to have styles associated to the divs that are not associated to a certain vi开发者_如何学Goew?

Thanks!


If you use a word view for a typical django view (a method) it is not good idea to create separate css file for each view (unless you have very specific application).

In general you need to create you css files in such way that:

  1. general styles that can be applied in many templates are not repeated in multiple css files
  2. it is easy for you to manage styles in couple of css files

There is no strict guideline to create css file per view or css file per template in Django as far as I know.

Basically pointing to some css file in head, which contains styles appropriate to a template is enough here. Of course you need to make sure that you provide correct path to this file.

You can make one general css with styles that are used by most of your templates and a series of specific css files that are valid only in some specialized templates.

I also advice to take a look at django-compress if you want to go with your site to broader audience - this app makes your static files (like css) smaller and also it helps to concatenate group of css and js files. This has some positive impact on performance without decreasing readability of your code.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜