Django urls straight to html template

后端 未结 5 1941
我在风中等你
我在风中等你 2021-02-01 01:58

Learning django & python.

Just set up a new site after doing the tutorial. Now for arguments sake say I want to add a bunch of About us, FAQ basic html pages with ve

5条回答
  •  孤城傲影
    2021-02-01 02:38

    One way to do this would be to write a single custom view that wraps the direct_to_template generic view. The wrapper could accept a parameter and accordingly form the name of the template and pass it to direct_to_template. This way you can route multiple pages with a single URL configuration.

    Something like this:

    url(r'^foo/(?P\w+).html$', 'my_static_wrapper', name = 'my_static_wrapper'),
    
    def my_static_wrapper(request, page_name):
        # form template name and call direct_to_template
    

    That said I suspect that there are better solutions out there though.

提交回复
热议问题