我正在建立我的第一個w d django網站。我的網站有一個博客部分,我想在網址中添加發布日期。目前,添加頁面時,URL變爲:example.com/blog/[slug],但我希望它是:example.com/blog/2015/11/19/[slug]添加日期到博客頁面的網址
我的博客頁面:
class BlogPage(Page):
main_image = models.ForeignKey(
'wagtailimages.Image',
null=True,
blank=True,
on_delete=models.SET_NULL,
related_name='+'
)
date = models.DateField("Post date")
intro = models.CharField(max_length=250)
body = RichTextField(blank=True)
search_fields = Page.search_fields + (
index.SearchField('intro'),
index.SearchField('body'),
)
content_panels = Page.content_panels + [
FieldPanel('date'),
ImageChooserPanel('main_image'),
FieldPanel('intro'),
FieldPanel('body'),
]
你知道如何將變量傳遞到url嗎?我可以幫助那部分,但我不知道如何提取日期的具體部分,並把它們放在網址中。 – Programmingjoe
這裏是文檔:https://docs.djangoproject.com/en/1.8/topics/http/urls/ – Programmingjoe
我沒有一個完整的解決方案,但我建議看看自定義的'路線'方法http://docs.wagtail.io/en/v1.2/reference/pages/model_recipes.html#adding-endpoints-with-custom-route-methods,或者可能用'RoutablePageMixin'做些事情:http:// docs .wagtail.io/en/v1.2/reference/contrib/routablepage.html – gasman