meeb/django-distill

Keyword arguments are not utilized properly in distill_path

Closed this issue · 2 comments

It looks like the following urlpatterns fails when the site is being generated:

urlpatterns = [
    distill_path(route='/', view=TemplateView.as_view(template_name='test.html'), name='index'),
]

It seems that runserver works fine though. I think the issue might be here: https://github.com/meeb/django-distill/blob/master/django_distill/renderer.py#L184, notice that k is not being used anywhere during the rendering, therefore neither the route nor the view gets forwarded properly in this case. It works fine when using positional arguments for the route and view instead of the named arguments. Nonetheless, in some cases using named arguments is unavoidable (e.g. if these arguments are coming from an unpacked dictionary).

meeb commented

Thanks for the issue. I'll add a test with your above example in and see if I can replicate the issue.

meeb commented

This error is caused by your usage of kwargs with distill_path(...) (and internally, Django's path(...)) when the parameters are actually args. See:

https://github.com/django/django/blob/b347dc63d5468564cbb7050461565f4f89032664/django/urls/conf.py#L61

This works in vanilla Django without django_distill because what you're doing is using Python to flatten the kwargs to args for you when you call path(...). Internally django_distill intercepts the call to path(...) via distill_path(...) and needs to keep the kwargs and args separate for use in the static file rendering later. The easiest fix for this is for you to use args as per the Django spec, so in your example a working example would be:

urlpatterns = [
    distill_path('/', TemplateView.as_view(template_name='test.html'), name='index'),
]

I've added a patch committed above that does support the use of the specific kwargs route and view (which will mean your code sample does work after the next release), however this is mostly so it directly matches the positional parameter flattening supported in bare Django rather than something I would advise you use.