【发布时间】:2018-06-14 17:45:42
【问题描述】:
在我的 urls.py 中,我有以下模式:
url(r'^$', views.index, name='index'),
url(r'^setup/$', views.index, name='index'),
两种模式最终都解析为同一个视图,因为逻辑是在控制器中处理的。视图有点像这样:
def index(request):
return request(request, 'index.html', {})
在我的 index.html 文件中,我加载了 Angular、我的 Angular 应用程序、路由和其他所有内容。
我的角度路线看起来像这样:
.when('/', {
controller : 'BaseController',
templateUrl : 'static/app_partials/base.html',
reloadOnSearch: false
})
.when('/products/', {
controller : 'ProductsController',
templateUrl : 'static/app_partials/products.html',
reloadOnSearch: false
})
现在,当我转到我的模式中的第一个 URL 时,一切正常,并且路由能够完美地加载模板,因为 url 是 http://example.com/static/app_partials/base.html,这正是文件所在的位置。
但是,第二个 URL 不起作用,因为现在调用的模板是 http://example.com/setup/static/app_partials/base.html,它不存在。
我该如何解决这个问题?我试图将整个 URL 与域和内容一起放入我的路由中,但随后出现不安全的 URL 错误。有什么帮助吗?谢谢。
【问题讨论】:
-
你可以使用绝对 URL,例如
/static/app_partials/base.html而不是像static/app_partials/base.html这样的相对网址。 -
@Alasdair - 这解决了这个问题。非常感谢。
标签: javascript python angularjs django