从templateURL在AngularJS指令加载HTML(在Django应用程序) [英] Loading html from templateURL in AngularJS directive (in a django app)

查看:106
本文介绍了从templateURL在AngularJS指令加载HTML(在Django应用程序)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何可以加载在AngularJS指令从 templateURL HTML在建的Django的应用程序。
每当我给在 templateURL 变量某些URL,它达到了Django的服务器。我怎样才能实现呢?我可以给 templateURL Django的URL变量指令和Django中有呈现HTML?什么是这样做的正确方法?

How can I load html from templateURL in an AngularJS directive in an app built on django. Whenever I give some URL in the templateURL variable, it is reaching the django server. How can I implement this? Can I give a django URL in templateURL variable in directives and render the HTML there in django? What is the proper way of doing this?

我的指令:

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

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

}});

这是在 someURL / test.html的到达Django的服务器,并返回404。

It is reaching the django server at someURL/test.html and returning a 404.

我可以用这种方式实现?

Can i Implement this way?

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

}});

和在Django urls.py

url(r'^test/$', TemplateView.as_view(template_name='test.html'))

这是这样做的好方法吗?什么是正确的方法是什么?

Is this a good way of doing this? What is the proper way?

推荐答案

做一件事:

克里特岛为您的项目的静态文件夹中。

Crete static folder for your project.

添加静态文件夹的urls.py

add Static folder to urls.py

然后给URL的指令为:

then give url in directive as:

templateUrl: 'static/test.html'

这篇关于从templateURL在AngularJS指令加载HTML(在Django应用程序)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆