[英]Can't load template from an Angular route in a Django project
In my urls.py , I have the following patterns: 在我的urls.py中 ,我具有以下模式:
url(r'^$', views.index, name='index'),
url(r'^setup/$', views.index, name='index'),
Both the patterns ultimately resolve to the same view, as the logic is handled in the Controllers. 两种模式最终都解析为同一视图,因为逻辑是在控制器中处理的。 The view kinda looks like something like this:
视图有点像这样:
def index(request):
return request(request, 'index.html', {})
In my index.html file, I load in Angular, my Angular App, the routes, and everything else. 在我的index.html文件中,我加载了Angular,Angular App,路线以及其他所有内容。
My angular routes look something like this: 我的角度路线看起来像这样:
.when('/', {
controller : 'BaseController',
templateUrl : 'static/app_partials/base.html',
reloadOnSearch: false
})
.when('/products/', {
controller : 'ProductsController',
templateUrl : 'static/app_partials/products.html',
reloadOnSearch: false
})
Now, when I go to the first URL in my pattern, everything works nicely, and the route is able to load the template perfectly, as the url is http://example.com/static/app_partials/base.html
, which is exactly where the file is. 现在,当我转到模式中的第一个URL时,一切运行良好,并且路由可以完美加载模板,因为该URL为
http://example.com/static/app_partials/base.html
,即文件的确切位置。
However, the second URL does not work, as the template being called now is http://example.com/setup/static/app_partials/base.html
, which does not exist. 但是,第二个URL不起作用,因为现在正在调用的模板是
http://example.com/setup/static/app_partials/base.html
,该模板不存在。
How can I fix this issue? 如何解决此问题? I have tried to put the whole URL in my routes, with the domain and stuff, but then I get a insecure URL error.
我试图将整个URL(包括域和内容)放入我的路由中,但是随后出现了一个不安全的URL错误。 Any help?
有什么帮助吗? Thanks.
谢谢。
Use absolute URLs (with a leading slash) instead of relative URLs. 使用绝对URL(带斜杠)而不是相对URL。
For example use /static/app_partials/base.html
instead of static/app_partials/base.html
例如,使用
/static/app_partials/base.html
而不是static/app_partials/base.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.