Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MasterPage like concept in python

We are developing a web based application in python on google app engine platform. I have different pages in web site. What I want is to have a master page like functionality like we have in asp.net where I have just on template and all other pages will use that. How can I do this? I am a beginner in python

like image 615
Ramesh Soni Avatar asked Jan 08 '10 04:01

Ramesh Soni


People also ask

What is the purpose of master page?

What are master pages? Master pages are used to create consistency from page to page in a document. Master pages typicially contain page headers, footers, margin and column guides, and other elements that occur on multiple pages in your document.

How do you create a master page in Python?

To create a master page, go to the Output tab and from the Master Page menu and select New Master Page.

What is a master page in web design?

Master pages allow you to create a consistent look and behavior for all the pages (or group of pages) in your web application. A master page provides a template for other pages, with shared layout and functionality. The master page defines placeholders for the content, which can be overridden by content pages.

How master page and content pages are connected?

The master page establishes a layout and includes one or more ContentPlaceHolder controls for replaceable text and controls. The content page includes only the text and controls that are merged at run time with the master page's ContentPlaceHolder controls.


2 Answers

I think you are exactly looking for "template extending".

  1. Create base/master html file in "templates" folder.

    This will be base/master file where all theme css,js , html layout tags exists.

  2. Add place holders for child html "content" in above base/master html

    {% block content %} {% endblock %}

  3. Add following code line in "child" template to use above base/master html

    {% extends 'path_to_base_html/base.html' %} {% block content %} Child html {% endblock %}

Thanks to this nice tutorial, http://tutorial.djangogirls.org/en/template_extending/index.html

like image 37
Sachin G. Avatar answered Sep 23 '22 07:09

Sachin G.


If you're using Django (or at least Django templates), Django template inheritance may be what you're looking for.

like image 189
Alex Martelli Avatar answered Sep 21 '22 07:09

Alex Martelli