Discoveringmypath
Discoveringmypath

Reputation: 1077

Best way to store web page content in database using Django and a single template for web pages

I'm building a web site and the bulk of the content will be the same general type and layout on the page. I'm going to use a single template to handle each post and the actual content will be stored in a database.

The content will just be html paragraphs, headers, sub headers, different lists, quotes, code blocks, etc.

Web pages will typically be the same or at least similar. All html components should follow the same guidelines to make sure everything looks and feels the same. Currently I'll be the only author, but in the future I plan to incorporate other authors as well.

At first I thought, just copy and paste this html content into a textfield in the database and I can add new posts/articles on the admin site.

Then I thought, maybe use a textfield and copy and paste json of a list of ['type': , 'content': ]. and then I can have the single template page iterate over this list and display the content based on the 'type'. My idea here is that it would shorten the data I have to add to the database by stripping the html tags out of the equation.

Considering I hope to have future authors as well, just curious of some ideas on how I can accomplish this to make it easy for myself to post new content.

Upvotes: 1

Views: 549

Answers (1)

vaeng
vaeng

Reputation: 140

That sounds pretty much exactly like the example of this fantastic tutorial by Miguel Grinberg. He sets up a flask environment to be used as his personal blog. With user log in and everything you would need.

Upvotes: 0

Related Questions