Django 如何在模板(Template)中使用settings中预定义的变量

在Django中编写模板(template)的时候, 有时候可能会用到settings中设定的变量, 比如说STATIC_URL。 此时, 如果你直接使用 是取不到值的。 那么怎么才能在模板中使用呢? 难道非得在每个view中添加到context中吗?

答案是否定的。 根据Django文档中所描述, 我们至少有两种方法可以直接使用。 http://docs.djangoproject.com/en/dev/howto/static-files/#referring-to-static-files-in-templates

Continue reading
  • Page 1 of 1

Samuel Chen

I am living in Wuhan with my wife and daughter.
Before 2010, I was living in Beijing for a long time.
My interesings are cloud technology, distributed system, data mining and mobile technologies.
In my spare time, I like to play football and swiming.
“Explorer. Dream. Discover. “ is my favorite quotation. And it is also the way I am looking for and doing.


Wuhan, China