meeb/django-distill

Usage of "include" in distill_url?

Closed this issue · 6 comments

Hey @meeb I've been using django_distill in a project and we want to include another package that uses django_distill using include(). But I'm getting failed to do that because instead of passing a view_func example MyVIew.as_view(), I'm passing a tuple i.e. include(package_name.urls). Can you please help me out? Is there any way I can get that possible using include() ?

Sorry! But I got a solution which is working i.e. By just appending the urlpatterns of package that uses django_distill in the my project urls and then running django_distill over it is perfectly working. If instead of appending the package urlpatterns to my project urlpatterns, there exists any solution? It would be a great help to me.
Thnx 😇

meeb commented

Hi, can you paste the error you get when you use include(...) please? Internally, django_distill's distill_path(...) and distill_url(...) functions just wrap on top of Django's own path(...) and url(...) functions so they should always work in the same context. If this isn't the case it likely requires fixing, or what you're trying to do wouldn't work with stock Django anyway. Either way, more information would help here. Cheers.

# all...imports

def get_index():
    return None

urlpatterns = [
    distill_url(
        r'OH/', include('openhub_django.urls'),
        name='community-openhub',
        distill_func=get_index,
    ), .....]

Running python manage.py runserver is raising no-error in rendering the page. And all the OH/ webpage is also getting opened. All the error is being raised when I run python manage.py distill-local public --force. It creates the static webpages for all the included urls mentioned in openhub_django.url but as soon as it completes generating those webpages at last it displays the following message:

.
.
.
Rendering page: openhub/openhub/portfolio_project/468/index.html -> /home/kvgarg/GSoC/community/public/openhub/openhub/portfolio_project/468/index.html ["text/html; charset=utf-8", 1712 bytes]  (renamed from "openhub/openhub/portfolio_project/468/")
Rendering page: openhub/openhub/portfolio_project/469/index.html -> /home/kvgarg/GSoC/community/public/openhub/openhub/portfolio_project/469/index.html ["text/html; charset=utf-8", 1693 bytes]  (renamed from "openhub/openhub/portfolio_project/469/")
Rendering page: openhub/openhub/portfolio_project/470/index.html -> /home/kvgarg/GSoC/community/public/openhub/openhub/portfolio_project/470/index.html ["text/html; charset=utf-8", 1685 bytes]  (renamed from "openhub/openhub/portfolio_project/470/")
Rendering page: openhub/openhub/organization/index.html -> /home/kvgarg/GSoC/community/public/openhub/openhub/organization/index.html ["text/html; charset=utf-8", 1667 bytes]  (renamed from "openhub/openhub/organization/")
Rendering page: openhub/openhub/org/1/index.html -> /home/kvgarg/GSoC/community/public/openhub/openhub/org/1/index.html ["text/html; charset=utf-8", 2591 bytes]  (renamed from "openhub/openhub/org/1/")
CommandError: Failed to render view: 'tuple' object is not callable

django_distill renderer.py https://github.com/mgrp/django-distill/blob/master/django_distill/renderer.py#L97

Sorry! But I got a solution which is working i.e. By just appending the urlpatterns of package that uses django_distill in the my project urls and then running django_distill over it is perfectly working. If instead of appending the package urlpatterns to my project urlpatterns, there exists any solution? It would be a great help to me.
Thnx innocent

Another solution is to use just url(..., include(...)). This one is also working.

meeb commented

Hi, sorry for the delay. Yes this looks like I could patch it to stop this occurring, I'll include a fix in the next release. The fix won't immediately resolve it for you though until the upstream projects you are include()ing update to the newer release, but your work-arounds are perfectly fine as well. Thanks for reporting it.

meeb commented

I've finally had time to look at this. While possible to handle I think I'm going to leave it raising an error. Technically you are using distill in the wrong place by including a sub-project of URLs and attempting to render it. This isn't how distill works, you use distill on single views not a group of included views. It could be patched to handle the event without error-ing, but, it probably should error really in this situation. Your work-around of just using url() is the correct answer. Thanks for reporting.