Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extend a django base template directly. #70

Open
pelme opened this issue Dec 3, 2024 · 1 comment
Open

Extend a django base template directly. #70

pelme opened this issue Dec 3, 2024 · 1 comment

Comments

@pelme
Copy link
Owner

pelme commented Dec 3, 2024

When wanting to use htpy with a django project with existing templates, it would be nice to have a helper to directly extend a django base template, something like:

import htpy as h
from htpy.django import extend_template

result = template_extend(
    'admin/base_site.html',
    breadcrumbs=h.div(".breadcrumbs"),
    coltype="colM",
    content=div('.module.report')[...],
) # result is a string with the blocks filled in. 

This can probably be implemented by just creating a template string dynamically like f"{{% extends {base_template}" %}}" and then creating a bunch of f"{{% block {name} %}}{htpy_contents}{{% endblock %}}"s dynamically and then passing that string to Template(X).render(..)`

@pelme
Copy link
Owner Author

pelme commented Dec 3, 2024

the values needs to be passed via context and not passed directly to Template to avoid security problems. how to deal with {{ block.super }} though? maybe it cannot be supported

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant