2

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 configuration 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?

2 Answers 2

4

Use JSON. Generate the CSS dynamically, using caching to reduce load.

Sign up to request clarification or add additional context in comments.

2 Comments

Where does the JSON go - in my static/js directory? Does my Django app reach into the directory to get the configuration? During development, can I have Django do a reload if the JSON configuration changes, and if so, how?
Ended up generating the Javascript and CSS dynamically. @gnibbler's comment reminded me that I've only got a few dozen users on a local intranet so the performance even without caching isn't going to be a problem.
0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.