好的,我学到了一点,现在可以在网上复制我的网站了。py,但我不喜欢在某些地方这样做。
2) 我希望能够从布局中调用函数。
以上任何建议都会很有帮助,提前谢谢你。
代码.py:
import web
import Universal
import Navigation
import Content
import Versions
urls = (
'/favicon.ico', 'icon',
'/', 'index',
'/Section1/index', 'Section1',
'/Section2/index', 'Section2',
'/Section3/index', 'Section3'
)
app = web.application(urls, globals(), autoreload=True)
render = web.template.render('templates/')#, base='Layout')
static = web.template.render('static/')
Main = web.template.render('templates/')
Section1 = web.template.render('templates/Section1/')
Section2 = web.template.render('templates/Section2/')
Section3 = web.template.render('templates/Section3/')
class static:
def GET(self):
return static()
#class icon:
# def GET(self):
# return static.favicon()
class index:
def GET(self):
vPage = '0'
vLevel = '0'
vSection = '0'
vHead = Universal.getHead(vSection)
vHeader = Universal.getHeader()
vNavBar = Universal.getNavBar()
vNavigation = Navigation.getNavigation(vLevel)
vContent = Content.getContent(vLevel)
vVersions = Versions.getVersions(vLevel)
vFooter = Universal.getFooter()
return Main.Layout(vHead, vHeader, vNavBar, vNavigation, vContent, vVersions, vFooter)
class Section1:
def GET(self):
vPage = '0'
vLevel = '1'
vSection = '1'
vHead = Universal.getHead(vSection)
vHeader = Universal.getHeader()
vNavBar = Universal.getNavBar()
vNavigation = Navigation.getNavigation(vLevel)
vContent = Content.getContent(vLevel)
vVersions = Versions.getVersions(vLevel)
vFooter = Universal.getFooter()
return Main.Section1.Layout(vHead, vHeader, vNavBar, vNavigation, vContent, vVersions, vFooter)
class Section2:
def GET(self):
vPage = '0'
vLevel = '2'
vSection = '2'
vHead = Universal.getHead(vSection)
vHeader = Universal.getHeader()
vNavBar = Universal.getNavBar()
vNavigation = Navigation.getNavigation(vLevel)
vContent = Content.getContent(vLevel)
vVersions = Versions.getVersions(vLevel)
vFooter = Universal.getFooter()
return Main.Section2.Layout(vHead, vHeader, vNavBar, vNavigation, vContent, vVersions, vFooter)
class Section3:
def GET(self):
vPage = '0'
vLevel = '3'
vSection = '3'
vHead = Universal.getHead(vSection)
vHeader = Universal.getHeader()
vNavBar = Universal.getNavBar()
vNavigation = Navigation.getNavigation(vLevel)
vContent = Content.getContent(vLevel)
vVersions = Versions.getVersions(vLevel)
vFooter = Universal.getFooter()
#return render.Layout(vHead, vHeader, vNavBar, vNavigation, vContent, vVersions, vFooter)
return Main.Section3.Layout(vHead, vHeader, vNavBar, vNavigation, vContent, vVersions, vFooter)
模板/Layout.html:
$def with (vHead, vHeader, vNavBar, vNavigation, vContent, vVersions, vFooter)
<html>
<head>
$:vHead
</head>
<body id="idBody">
<table id="idTableMain">
<tr id="idHeaderRow">
<td id="idHeaderRowCenter" colspan="3">
$:vHeader
</td>
</tr>
<tr id="idNavigationRow">
<td id="idNavigationBar" colspan="3">
$:vNavBar
</td>
</tr>
<tr id="idCenterRow">
<td id="idCenterRowLeft">
<h4>
Navigation
</h4>
$:vNavigation
</td>
<td id="idCenterRowMain">
$:vContent
</td>
<td id="idCenterRowRight">
<h4>
Information
</h4>
This was written with Python 2.7 and web.py.<br><br>
Other versions of this page are here:<br>
$:vVersions
</td>
</tr>
<tr id="idFooterRow">
<td id="idFooterMain" colspan="3">
$:vFooter
</td>
</tr>
</table>
</body>
</html>
通用.py
def getHead(vSection):
vResult = '<meta http-equiv=\"Content-Type\" content=\"text/html; charset=ISO-8859-1\">'
vResult += '<link href=' + getCSS(vSection) + ' rel=\"stylesheet\" type="text/css">'
return vResult
def getCSS(vSection):
if vSection == '1':
vResult = '/static/Section1/Section1.css'
elif vSection == '2':
vResult = '/static/Section2/Section2.css'
elif vSection == '3':
vResult = '/static/Section3/Section3.css'
else:
vResult = '/static/Main.css'
return vResult
def getHeader():
vResult = '<img id=\"idLogo\" src=' + getLogo() + '>'
return vResult
def getNavBar():
vResult = '<a class=\'navBar\' href=\'/index\'>Home</a>'
vResult += '<a class=\'navBar\' href=\'/Section1/index\'>Web Programming</a>'
vResult += '<a class=\'navBar\' href=\'/Section2/index\'>Private Projects</a>'
vResult += '<a class=\'navBar\' href=\'/Section3/index\'>Downloadable Projects</a>'
return vResult