小编mit*_*thu的帖子

从AngularJS指令中的templateURL加载html(在django应用程序中)

如何templateURL在基于django构建的应用程序中的AngularJS指令中加载html .每当我在templateURL变量中给出一些URL时,它就会到达django服务器.我该如何实现呢?我可以在templateURL变量指令中给出一个django URL 并在django中呈现HTML吗?这样做的正确方法是什么?

我的指示:

app.directive('test', function()
{
  return{

  restrict: 'E',
  templateUrl: 'test.html'

}});
Run Code Online (Sandbox Code Playgroud)

它到达django服务器someURL/test.html并返回404.

我能用这种方式实现吗?

app.directive('test', function()
{
  return{
  restrict: 'E',
  templateUrl: 'app/test'

}});
Run Code Online (Sandbox Code Playgroud)

在django urls.py

url(r'^test/$', TemplateView.as_view(template_name='test.html'))
Run Code Online (Sandbox Code Playgroud)

这是一个很好的方法吗?什么是正确的方法?

python django angularjs angularjs-directive

4
推荐指数
1
解决办法
2502
查看次数

标签 统计

angularjs ×1

angularjs-directive ×1

django ×1

python ×1