From 24698741e26984949b085c578f8f3ca11025259d Mon Sep 17 00:00:00 2001 From: meeb Date: Mon, 19 Dec 2022 11:58:59 +1100 Subject: [PATCH] tweak readme for new feature --- README.md | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 448c06a..0af5e4a 100644 --- a/README.md +++ b/README.md @@ -142,13 +142,10 @@ urlpatterns = ( # '' is not a valid file name! override it to index.html distill_file='index.html'), # e.g. /post/123-some-post-title using named parameters - distill_path('post/-', + distill_path('post/-.html', PostView.as_view(), name='blog-post', - distill_func=get_all_blogposts, - # url does not end in / nor has any file extension - # distill_file with format params is used here - distill_file="post/{blog_id}-{blog_title}.html"), + distill_func=get_all_blogposts), # e.g. /posts-by-year/2015 using positional parameters # url ends in / so file path will have /index.html appended distill_path('posts-by-year//', @@ -198,6 +195,25 @@ urlpatterns = ( ) ``` +### Parameters in file names + +You can standard Python string formatting in `distill_file` as well to enable +you to change the output file path for a file if you wish. Note this does not +update the URL used by Django so if you use this make sure your `path` pattern +matches the `distill_file` pattern or your links might not work in Django. An +example: + +```python +# Override file path with parameters. Values are taken from the URL pattern +urlpatterns = ( + distill_path('post/-.html', + PostView.as_view(), + name='blog-post', + distill_func=get_all_blogposts, + distill_file="post/{blog_id}-{blog_title}.html" +) +``` + ### Non-standard status codes All views rendered by `django-distill` into static pages must return an HTTP 200 status