June 18th, 2013, 11:03 AM
Help needed with web app architecture
I am working on a web app that acts a static content generator. Here is how it works:
I have a set of HTML files. All the static content is stored in a database. For each piece of content in the database, I have a placeholder token in the HTML file. So whenever we want to generate the files HTML files, I want to call in the values from the database, replace the placeholders with the real text and then save the HTML files. The content from the database will be returned through a web service as JSON. So, I don't have to worry about the database connection part.
My question is what is the best way to do this. Here is what I was thinking:
1. Create all the HTML files with placeholders.
2. Import the content of an HTML file as a string.
3. Fetch the JSON with real values.
4. Map the real values to the placeholders.
5. Save the string back to the HTML file.
Is this the best way to do this? Is there something that can be done here in a better way? Share your thoughts and suggestion about this architecture.
June 18th, 2013, 04:17 PM
A better way is to use a template engine such as Mako, which basically does all that stuff for you in a nicer way.