Javascript Templating Package

73 visualizações
Ir para a primeira mensagem não lida

Nick Sarbicki

não lida,
11/10/2016, 09:33:2111/10/16
para Django developers (Contributions to Django itself)
Hi Everyone,

We were tasked at work some time ago with tidying up a legacy Django project. Part of the projects JS relied heavily on Django variables and settings and we were seeing frequent large variable JSON dumps in the templates.

We cleaned this up and ended up designing a small package which allowed us to generate Javascript files through the Django templating engine when requested by the client.

Since then we've started finding ourselves thinking about using this package more and more.

So I was wondering, is this something that the community would be interested in? It's not open source yet but we're considering opening up the particular package (not least so its more available for us).

If it's not at all of interest, why? Is there a big disadvantage to generating Javascript through the templating engine? (assume you, and not the client, control the variables going in.

Daniel Moisset

não lida,
11/10/2016, 10:12:2211/10/16
para django-d...@googlegroups.com
Hi Nick, I'm not sure what kind of generation are you suggesting. What I've used a couple of times is creating a template tag to convert a json-like data structure in the context to a javascript object, so in the template I have something like this in a <script> tag:

var foo = {% foo|to_json %}; /* foo comes from python context typically a compelx nexted dict/list */
// code that uses the data in foo

Are you suggesting something like this or something different?



--
You received this message because you are subscribed to the Google Groups "Django developers (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-developers+unsubscribe@googlegroups.com.
To post to this group, send email to django-developers@googlegroups.com.
Visit this group at https://groups.google.com/group/django-developers.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/04d4d42d-3bfa-47c6-9ac7-e9d801de9286%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Daniel F. Moisset - UK Country Manager
Skype: @dmoisset

Nick Sarbicki

não lida,
11/10/2016, 10:28:2011/10/16
para django-d...@googlegroups.com
Hi Daniel,

This is a separate idea. Instead of relying on JSON dumps, we actually generate an entire JS script via the engine.

The flow is along the lines of:

> Client makes request

> Django receives request and renders an HTML page which it passes to the client.

> The given HTML page has a script tag which requests a javascript file from our server.

> Django receives this request and, instead of serving a static javascript file, renders a javascript file via the templating engine which it then passes to the client.

This allows us to have more control over the client side scripts based on what is happening server side. 

It's a bit niche - but it cleared up a lot of the legacy JS held in massive script tags which were overly wasteful and required a lot of tampering based on server side variables.

On Tue, Oct 11, 2016 at 3:11 PM Daniel Moisset <dmoi...@machinalis.com> wrote:
Hi Nick, I'm not sure what kind of generation are you suggesting. What I've used a couple of times is creating a template tag to convert a json-like data structure in the context to a javascript object, so in the template I have something like this in a <script> tag:

var foo = {% foo|to_json %}; /* foo comes from python context typically a compelx nexted dict/list */
// code that uses the data in foo

Are you suggesting something like this or something different?


On 11 October 2016 at 14:33, Nick Sarbicki <nick.a....@gmail.com> wrote:
Hi Everyone,

We were tasked at work some time ago with tidying up a legacy Django project. Part of the projects JS relied heavily on Django variables and settings and we were seeing frequent large variable JSON dumps in the templates.

We cleaned this up and ended up designing a small package which allowed us to generate Javascript files through the Django templating engine when requested by the client.

Since then we've started finding ourselves thinking about using this package more and more.

So I was wondering, is this something that the community would be interested in? It's not open source yet but we're considering opening up the particular package (not least so its more available for us).

If it's not at all of interest, why? Is there a big disadvantage to generating Javascript through the templating engine? (assume you, and not the client, control the variables going in.

--
You received this message because you are subscribed to the Google Groups "Django developers (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-develop...@googlegroups.com.
To post to this group, send email to django-d...@googlegroups.com.
--
Daniel F. Moisset - UK Country Manager
Skype: @dmoisset

--
You received this message because you are subscribed to the Google Groups "Django developers (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-develop...@googlegroups.com.
To post to this group, send email to django-d...@googlegroups.com.
Responder a todos
Responder ao autor
Reencaminhar
0 mensagens novas