首页 \ 问答 \ 哪个Django模板布局更好?(Which Django template layout is better? [closed])

哪个Django模板布局更好?(Which Django template layout is better? [closed])

哪种布局更好(Django 1.4+),:

project/templates/base.html
# project/templates/app/base.html # overriding some_app at project level, optional
project/app/templates/app/base_app.html
project/app/templates/app/base_app_index.html
  • base_app_index.html扩展了base_app.html - 应用级别
  • base_app.html扩展base.html - 项目级别。

或者像这样可用 (没有一个项目的应用程序之间共享)

project/app/templates/app/base_app.html
project/app/templates/app/base_app_index.html
  • 只需base_app_index.html扩展base_app.html

参考文献:

来自Django Docs

  • 创建一个base.html模板,其中包含您网站的主要外观。
  • 为您网站的每个“部分”创建一个base_SECTIONNAME.html模板。 例如,base_news.html,base_sports.html。 这些模板都扩展了base.html,并包含特定于部分的样式/设计。
  • 为每种类型的页面创建单独的模板,例如新闻文章或博客条目。 这些模板扩展了相应的部分模板。

来自Django Best Pratices

位置模板通常位于应用程序内部或项目根级别的两个位置之一。 我们建议您将所有模板保留在项目模板目录中,除非您计划将应用程序包含在多个项目中(或将其作为开源“可重用”应用程序开发)。 在这种情况下,在应用程序中提供一组示例模板可能会有所帮助,使其可以开箱即用或作为其他开发人员的示例。

来自两个Django的Scoops

  • 每个应用都有一个base_.html模板。 应用级基本模板共享一个公共父级base.html。
  • 应用内的模板共享一个公共父base_.html模板。
  • 与base.html处于同一级别的任何模板都会继承base.html

Which layout is better(Django 1.4+),:

project/templates/base.html
# project/templates/app/base.html # overriding some_app at project level, optional
project/app/templates/app/base_app.html
project/app/templates/app/base_app_index.html
  • base_app_index.html extends base_app.html -- app level
  • base_app.html extends base.html -- project level.

or usable like this(no share between apps with one project)

project/app/templates/app/base_app.html
project/app/templates/app/base_app_index.html
  • just base_app_index.html extends base_app.html

References:

From Django Docs:

  • Create a base.html template that holds the main look-and-feel of your site.
  • Create a base_SECTIONNAME.html template for each “section” of your site. For example, base_news.html, base_sports.html. These templates all extend base.html and include section-specific styles/design.
  • Create individual templates for each type of page, such as a news article or blog entry. These templates extend the appropriate section template.

From Django Best Pratices:

Location Templates typically live in one of two places, inside the application or at the root level of a project. We recommend keeping all your templates in the project template directory unless you plan on including your application in multiple projects (or developing it as a open source “reusable” application). In that case, it can be helpful to ship with a set of sample templates in the application, allowing it to work out-of-the-box or serving as an example for other developers.

From Two Scoops of Django:

  • Each app has a base_.html template. App-level base templates share a common parent, base.html.
  • Templates within apps share a common parent base_.html template.
  • Any template at the same level as base.html inherits base.html

原文:https://stackoverflow.com/questions/23199319
更新时间:2021-10-22 10:10

最满意答案

我相信这意味着你绑定到任何绑定上下文的根。 因此,如果您在作为某种列表控件的一部分的datatemplate中使用此语法,那么您将绑定到父控件(列表控件)绑定到的任何根级别。


I believe it means you are binding to the root of whatever the binding context is. So if you use this syntax in a datatemplate that is part of some sort of list control, you would be binding to the root level of whatever the parent control (the list control) was binding to.

相关问答

更多
  • 字段不是绑定源规范的一部分 公共语言运行时(CLR)对象 您可以绑定到任何公共语言运行时(CLR)对象的公共属性,子属性以及索引器。 绑定引擎使用CLR反射来获取属性的值。 或者,实现ICustomTypeDescriptor或具有已注册的TypeDescriptionProvider的对象也可以使用绑定引擎。 有关如何实现可用作绑定源的类的更多信息,请参阅本主题后面的为绑定源实现类。 动态对象 您可以绑定到实现IDynamicMetaObjectProvider接口的对象的可用属性和索引器。 如果您可以在 ...
  • 为什么不问问文档 : 属性的子属性可以通过类似于C#中使用的语法来指定。 例如,子句Path = ShoppingCart.Order将绑定设置为对象或属性ShoppingCart的子属性Order。 当源是集合视图时 ,可以用斜线(/)指定当前项目。 例如,子句Path = /设置绑定到视图中的当前项目。 当源是集合时,此语法指定默认集合视图的当前项目。 (为方便起见添加了Collection视图链接) 这就像它得到的一样简洁和完整。 使用. 对其中一件物品的收藏品进行记号甚至没有意义。 例如Collec ...
  • 这是因为selectionchanged尚未触发,因此selecteditem仍然为null。 private void c_SelectionChanged(object sender, SelectionChangedEventArgs e) { MessageBox.Show(this.c.SelectedItem.ToString()); } 如果您是WPF的新手,我建议您去看看MVVM模式。 这里有一个非常好的介绍视频: http : //blog.lab49.com/archives/2 ...
  • 除非您使用MVVM,否则不需要这样做,但无论如何,使用可以创建List作为窗口的属性,如此 public List List {get;set;} 然后在XAML中你可以使用RelativeSource绑定到窗口:
    我相信这意味着你绑定到任何绑定上下文的根。 因此,如果您在作为某种列表控件的一部分的datatemplate中使用此语法,那么您将绑定到父控件(列表控件)绑定到的任何根级别。 I believe it means you are binding to the root of whatever the binding context is. So if you use this syntax in a datatemplate that is part of some sort of list control ...
  • 得到它了:
    问题1 : 没有,没有区别。 {Binding xyz}与{Binding Path=xyz} ,它几乎就像一个捷径。 但它只能用于你在绑定中写的第一件事,例如,你不能这样做: {Binding ElementName=myElement, xyz} 相反,你会这样做: {Binding ElementName=myElement, Path=xyz} 甚至更好: {Binding xyz, ElementName=myElement} 这是一个相关的问题。 问题2 : 你所做的是正确的,你的人员集合 ...
  • 我认为是因为你试图定义一个匿名函数。 控制台没有未来的引用方式,所以它是一个毫无意义的努力,你定义一个你无法调用的函数。 如果将其定义为变量,则可以: var a = function () {}.bind(null); 我也不认为它的约束力相关。 定义一个没有绑定的匿名函数,你有同样的错误 编辑 以关键字“function”开头的语句必须是有效的函数声明语句。 这需要函数的名称。 在表达式(或表达式语句)中,该规则是不同的; 不需要名称,因为该函数在该上下文中充当值。 那时不需要名字。 来自@Poi ...
  • @Silva,你的直觉是正确的,幕后发生了一些事情。 我只是在Pete Brown(微软开发者福音传教士)博客上发现的一篇博文中清楚地看到了这一点: http://10rem.net/blog/2010/12/17/puff-the-magic-poco-binding-and-inotifypropertychanged-in-wpf 查看他写关于PropertyDescriptor类的部分。 他还提到,与使用在viewmodel类上实现INotifyPropertyChanged接口的更常规方法相比,它 ...
  • Lang绑定的解析器位于https://github.com/slodge/MvvmCross/blob/v3/Cirrious/Cirrious.MvvmCross.Binding/Parse/Binding/Lang/MvxLanguageBindingParser.cs 它为每个Lang绑定解析4件事: 键 - 文本查找 - 用作Converter的参数 Source - 默认为“TextSource” - 实际上这用作绑定路径 转换器 - 使用的值转换器(默认为“语言”) FallbackValue ...

相关文章

更多

最新问答

更多
  • 获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
  • 如何通过引用返回对象?(How is returning an object by reference possible?)
  • 矩阵如何存储在内存中?(How are matrices stored in memory?)
  • 每个请求的Java新会话?(Java New Session For Each Request?)
  • css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
  • 无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
  • xcode语法颜色编码解释?(xcode syntax color coding explained?)
  • 在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
  • 从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
  • 从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
  • 西安哪有PLC可控制编程的培训
  • 在Entity Framework中选择基类(Select base class in Entity Framework)
  • 在Android中出现错误“数据集和渲染器应该不为null,并且应该具有相同数量的系列”(Error “Dataset and renderer should be not null and should have the same number of series” in Android)
  • 电脑二级VF有什么用
  • Datamapper Ruby如何添加Hook方法(Datamapper Ruby How to add Hook Method)
  • 金华英语角.
  • 手机软件如何制作
  • 用于Android webview中图像保存的上下文菜单(Context Menu for Image Saving in an Android webview)
  • 注意:未定义的偏移量:PHP(Notice: Undefined offset: PHP)
  • 如何读R中的大数据集[复制](How to read large dataset in R [duplicate])
  • Unity 5 Heighmap与地形宽度/地形长度的分辨率关系?(Unity 5 Heighmap Resolution relationship to terrain width / terrain length?)
  • 如何通知PipedOutputStream线程写入最后一个字节的PipedInputStream线程?(How to notify PipedInputStream thread that PipedOutputStream thread has written last byte?)
  • python的访问器方法有哪些
  • DeviceNetworkInformation:哪个是哪个?(DeviceNetworkInformation: Which is which?)
  • 在Ruby中对组合进行排序(Sorting a combination in Ruby)
  • 网站开发的流程?
  • 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
  • 条带格式类型格式模式编号无法正常工作(Stripes format type format pattern number not working properly)
  • 透明度错误IE11(Transparency bug IE11)
  • linux的基本操作命令。。。