开发者

Why Django static and media folders aren't pre-configured?

开发者 https://www.devze.com 2023-02-19 00:54 出处:网络
I was presenting a Django demonstration to my brother and he asked me the following question(s): \"Why Django static and media fold开发者_开发问答ers aren\'t pre-configured? It\'s purpose aren\'t to b

I was presenting a Django demonstration to my brother and he asked me the following question(s): "Why Django static and media fold开发者_开发问答ers aren't pre-configured? It's purpose aren't to be a convention over configuration framework? Why I am supposed to configure these things every time I start a Django project?"

I couldn't answer to him. Does anyone can?

P.S: I don't mean to compare Django with other frameworks. I'm just trying to understand why these design decisions were made;


Django is very definitely not a convention over configuration framework. Your brother is perhaps thinking of Rails, which does follow that principle - but Django follows the Python principle of "explicit is better than implicit".


Because django shouldn't distribute media files anyway. When you read the documentation you can see that the static files should (and must) be distributed by your server engine and/or by some kind of CDN when you are in production. Django, is just here to process your pages but not your media. And when you are in development, indeed, you have to use django to distribute static files. But you can use a python script to generate it, and manage it. For me, one of the best is: Django mediagenerator. This will let your files like they are in dev mode, but this will optimize it in production.

0

精彩评论

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

关注公众号