web.pyを使用してウェブサイトを再作成する方法を学習しようとしていますが、必要な構文が見つからない。webpy(2.7)を使用してテンペット内でhtmlを呼び出す方法
純粋なHTMLを含め、私が使用した他の言語でも、スクリプト、オブジェクト、パッケージ、またはビューを呼び出してHTMLをレンダリングする方法があります。だから私はPythonでこれをどうやってやるのだろう?
レイアウト以外のファイルを静的ディレクトリに再配置し、HTMLを何らかの形で書き込んだり返すPythonファイルとして書き直したり、アクセスする方法がある場合はURL処理のサブファイルを含めることができますそのようにhtmlにロードしてください。
私はそのセクションに必要なHTMLを書いたり、呼び出すスクリプトを実行するために.pyを呼び出すことを望んでいましたが、私のニーズを満たす例は見つけられないようです。
ご協力いただきありがとうございます。
今私のコードのようなものになります。 code.py
import web
urls = (
'/favicon.ico', 'icon',
'/', 'index',
'/index', 'index'
)
app = web.application(urls, globals(), autoreload=True)
render = web.template.render('templates/')#, base='Layout')
static = web.template.render('static/')
Main = web.template.render('templates/')
MainContent = web.template.render('Content/')
class static:
def GET(self):
return static()
class icon:
def GET(self):
return static.favicon()
class index:
def GET(self):
return Main.Layout(0, 0, 'Main.css')
if __name__ == '__main__':
app.run()
/templates/Layout.html
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<link href="static/$vCSS" rel="stylesheet" type="text/css">
</head>
<body id="idBody">
<table id="idTableMain">
<tr id="idHeaderRow">
<td id="idHeaderRowCenter" colspan="3">
<img src="static/logo.jpg"/>
</td>
</tr>
<tr id="idNavigationRow">
<td id="idNavigationBar" colspan="3">
<!--Display /templates/NavBar.html -->
</td>
</tr>
<tr id="idCenterRow">
<td id="idCenterRowLeft">
<h4>
Navigation
</h4>
<!--Display /templates/Navigation.html -->
</td>
<td id="idCenterRowMain">
<!--Display /templates/Content/Content_index.html -->
</td>
<td id="idCenterRowRight">
<h4>
Information
</h4>
This was written with Python.<br><br>
Other versions of this page are here:<br>
<!--Display /templates/Versions_index.html -->
</td>
</tr>
<tr id="idFooterRow">
<td id="idFooterMain" colspan="3">
<!--Display /templates/Footer.html -->
</td>
</tr>
</table>
</body>
</html>
戻ってきて、その後、web.pyのドキュメントで入手可能な例に従ってくださいより具体的な質問があります。 – pbuck
私が見つけたものはこれをカバーしていません。データベースにスキップします。 – Kamurai
これは十分に具体的な質問ですが、web.pyとpythonをよく知っている皆さんにとって、明白で簡単なものです。 私はちょっと緑色だから、すべてのコードを変数に入れてメインの.pyファイルに渡すのではなく、これをどうやって行うのかに関するガイダンスを使うことができます。回答。 – Kamurai