how do I share configuration data between Javascript, Python, and CSS in my Django app?
I have Javascript, Django templates, Python code, and CSS which all work with the same configuration data. Where's the best place to configure it?
Specifically, I have a browser-side entry widget in Javascript which controls an embedded Java app. When the user is done, the Javascript asks the Java applet for an image of the result, which will be embeded in the HTML. The user can specify if the image should be small, medium, or large. That image and the choice are sent via an AJAX call to my Django app, which does some input validation. When the HTML is displayed it includes my CSS, which has special a[href^=http://internal.server] markup to show those images in a different way than other images.
While someone asked a similar question, the answers were either: "use a DSL" or "use a format like XML or JSON." Neither of which work with CSS.
The two solutions I came up with are:
- put the data in Python and have it generate the HTML through a Django form/template. Also have Django dynamically generate the Javascript configuration and generate that CSS.
I don't like this because I would rather serve all my Javascript and CSS statically.
- Introduce a build step where conf开发者_如何学Goiguration data gets applied to a template to build the respective Javascript, HTML, CSS, and Python files.
Which makes things more complicated because I'll have special "*.in" or such files which build the actual files, and everyone will have to watch out that they know which files are the ones to edit.
What do you do?
Use JSON. Generate the CSS dynamically, using caching to reduce load.
I think an really good approach would be to effectively have a DSL expressed indirectly via JSON data structures laid out using some sort of coding convention, coupled with a separate build step that used that to create the configuration files needed. If the tool(s) for this build step were written in Python, creating, maintaining, and enhancing it or them ought to be relatively easy.
精彩评论