You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm finding often want to embed html pages in the file alongside the code. Currently the only way is to define it in a constant at the top, or put it in the return value in the view - both of which obscure/bloat the code.
I'm finding I often want to render and return template strings, and although the boilerplate for that isn't particularly cumbersome, it is something I usually have to look up.
I think these can be addressed in one solution:
Defer html/template definition - set them at the bottom of the file by attaching to the app (an object already known in the view)
Do it in a way we can identify convert should write it into an actual html template file
View functions can render those templates
Ideally other templates can also refer to those in extends and include tags
Build this using or on top of django.template.loaders.locmem.Loader, and add this as the priority first loader in settings
Here app.render would be a wrapper for django.shortcuts.render, which saves an import and inserts the current request object - I think that should be available in the app. If not, maybe importing django.shortcuts.render would make more sense.
When we run convert, it can then write these templates out into text files, and rewrite app.render into a straight call to render. It will also need to remove our loader from the settings.
The text was updated successfully, but these errors were encountered:
Two related issues:
I think these can be addressed in one solution:
app
(an object already known in the view)convert
should write it into an actual html template fileextends
andinclude
tagsSuggested syntax:
Build this using or on top of
django.template.loaders.locmem.Loader
, and add this as the priority first loader in settingsHere
app.render
would be a wrapper fordjango.shortcuts.render
, which saves an import and inserts the currentrequest
object - I think that should be available in theapp
. If not, maybe importingdjango.shortcuts.render
would make more sense.When we run
convert
, it can then write these templates out into text files, and rewriteapp.render
into a straight call torender
. It will also need to remove our loader from the settings.The text was updated successfully, but these errors were encountered: