Django and Angular follow MVC (this way or another..) patterns, and therefore should separate HTML from code-behind.
But when browsing Django source code you can easily find:
class ClearableFileInput(FileInput):
....
template_with_initial = u'%(initial_text)s: %(initial)s %(clear_template)s<br />%(input_text)s: %(input)s'
template_with_clear = u'%(clear)s <label for="%(clear_checkbox_id)s">%(clear_checkbox_label)s</label>'
Instead of write a template and render it with Context.
or
def as_table(self):
"Returns this form rendered as HTML <tr>s -- excluding the <table></table>."
return self._html_output(
normal_row = u'<tr%(html_class_attr)s><th>%(label)s</th><td>%(errors)s%(field)s%(help_text)s</td></tr>',
error_row = u'<tr><td colspan="2">%s</td></tr>',
row_ender = u'</td></tr>',
help_text_html = u'<br /><span class="helptext">%s</span>',
errors_on_separate_row = False)
Instead of using templatetags, or use an external template.
Same with AngularJS, in their samples on the homepage you find:
this.addPane = function(pane) {
if (panes.length == 0) $scope.select(pane);
panes.push(pane);
}
},
template:
'<div class="tabbable">' +
'<ul class="nav nav-tabs">' +
'<li ng-repeat="pane in panes" ng-class="{active:pane.selected}">'+
'<a href="" ng-click="select(pane)">{{pane.title}}</a>' +
'</li>' +
'</ul>' +
'<div class="tab-content" ng-transclude></div>' +
'</div>',
replace: true
Instead of just using templateUrl and than write the template in a separate file and not inside the code.
Is there a good reason for this? or some other reasonable cause?
I myself don't find one, when writing widgets/directives I manage to separate the html from the code and everything works as expected.
This is obviously a bad pattern; in case of django there was an effort to fix it in a GSoC project, but it struggled because django templates are slow, simple string formatting is much faster and using templates for rendering fields was proven to be a real bottleneck. as_table
looks like a leftover that is kept in source code for backwards compatibility; developers don't need to use it.
I don't have experience with AngularJS, but it may be the case that the template in a separate file mean an extra HTTP request.