How to write a single view function to render multiple html from diferent urls path?

前端 未结 3 571
生来不讨喜
生来不讨喜 2021-01-24 13:24

I am trying to avoid self coping of views functions but have no idea ho to do it. My views have a minor differences and there is definitely a way to render html pages with a si

3条回答
  •  悲&欢浪女
    2021-01-24 13:48

    You can capture a slug in the URL and use it to determine which template to render.

    path('', views.general_page, ...)
    

    ...

    def general_page(request, slug):
        return render(request, 'website/{}.html'.format(slug))
    

提交回复
热议问题