Flask Snippets

CMS Pages

By kfk filed in Utilities

An idea to create pseudo dynamic text for pseudo static html pages (index, about us, contact, etc.).

Below the sqlalchemy models:

class Page(Base):
	id Column(Integer, primary_key=True)
	name = Column(String())
	page_snippets = relationship('PageSnippets', backref='pages', lazy='dynamic')

class PageSnippets('base')
	id Column(Integer, primary_key=True)
	snippet = Column(String())
	language = Column(String())

The view:

def a_page(page_id):
	page = Page.query.filter_by(id=page_id).one()
	page_snippets = page.page_snippets
	return render_template('a_page.html', page_snippets=page_snippets)

In the template:

<div class="footer">

A jinja macro could be used to filter languages.

This snippet by kfk can be used freely for anything you like. Consider it public domain.