我遇到了一个奇怪的问题,不确定为什么会发生。
这是我的模特:
class PostIndexPage(RoutablePage):
max_count = 1
parent_page_types = []
intro = RichTextField(blank=True)
content_panels = Page.content_panels + [
FieldPanel('intro', classname="full")
]
@route(r'^posts/$')
def main(self, request):
from django.shortcuts import render
return render(request, self.get_template(request), self.get_context(request))
我在该模型中定义了路由,但似乎没有作用。http://127.0.0.1:8000/post-index-page/-旧网址仍以旧方式工作http://127.0.0.1:8000/posts/-却没有(404,未找到)。
你知道我在做什么错吗?
由RoutablePage上的@route
定义的URL路由是相对于页面的常规路径的,这取决于页面的标记和在页面树中的位置。如果您使用段post-index-page
创建了可路由页面,则posts
路由将位于/post-index-page/posts/
。
如果您希望视图保留为完全固定的URL,则始终可以将其定义为标准Django视图。