无法从Django项目中的角度路由加载模板

2024-06-15 13:54:23 发布

您现在位置:Python中文网/ 问答频道 /正文

在我的网址.py,我有以下模式:

url(r'^$', views.index, name='index'),
url(r'^setup/$', views.index, name='index'),

这两种模式最终解析为同一个视图,因为逻辑在控制器中处理。景色有点像这样:

def index(request):
    return request(request, 'index.html', {})

在我的索引.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,它不存在。你知道吗

如何解决此问题?我试图把整个网址在我的路线,与域和东西,但后来我得到一个不安全的网址错误。有什么帮助吗?谢谢。你知道吗


Tags: 文件nameappurlbaseindexrequesthtml
1条回答
网友
1楼 · 发布于 2024-06-15 13:54:23

使用绝对URL(带前导斜杠)而不是相对URL。你知道吗

例如,使用/static/app_partials/base.html而不是static/app_partials/base.html

相关问题 更多 >