Skip to content

Commit

Permalink
tweak readme for new feature
Browse files Browse the repository at this point in the history
  • Loading branch information
meeb committed Dec 19, 2022
1 parent 0e6a436 commit 2469874
Showing 1 changed file with 21 additions and 5 deletions.
26 changes: 21 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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/<int:blog_id>-<slug:blog_title>',
distill_path('post/<int:blog_id>-<slug:blog_title>.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/<int:year>/',
Expand Down Expand Up @@ -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/<int:blog_id>-<slug:blog_title>.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
Expand Down

0 comments on commit 2469874

Please sign in to comment.