I'm currently concatenating adjacent cells in excel to repeat common HTML elements and divs - it feels like I've gone down a strange excel path in developing my webpage, and I was wondering if an experienced web designer could let me know how I might accomplish my goals for the site with a more conventional method (aiming to use python and mysql).
I have about 40 images in my site. On this page I want to see them all lined up in a grid so I have three divs next to each other on each row, all floating left.
Instead of manually typing all the code needed for each row of images, I started concatenating repeating portions of the code with distinct portions of the code. I took the four div classes and separated the code that would need to change for each image (src="XXX" and
"XXX").
Example:
> Column D Column E Column F
> '1 <div> <img src=" filename.jpg "></div>'
The formula to generate my HTML looks like this:
= D1 & E1 & F1
I'm sure it would be easier to create a MySQL database with the filepaths and attributes saved for each of my images, so I could look through the data with a scripting language. Can anyone offer their advice or a quick script for automating the html generation?
Wow, that sounds really painful.
If all you have is 40 images that you want to generate HTML for, and the rest of your site is static, it may be simplest just to have a single text file with each line containing an image file path. Then, use Python to look at each line, generate the appropriate HTML, and concatenate it.
If your site has more complex interaction requirements, then Django could be the way to go. Django is a great Python web app framework, and it supports MySQL, as well as a number of different db backends.
You could keep these and only these images in their own directory and then use simple shell scripts to generate that section of static html.
Assuming you already put the files in place maybe like this:
cp <all_teh_kitteh_images> images/grid
This command will generate html
for file in images/grid/*.jpg ; do echo "<div><img src=\"$file\"></div>" ; done
Oh, I'm sorry, I missed the python part of your question (IMO MySQL is overkill, you have no relations, don't use a relational database) Here is the same thing in python.
import glob
for file in glob.glob('images/grid/*.jpg'):
print "<div><img src=\"%s\"></div>" % file
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With