私はシンプルなウェブサイトのデモをしようとしていますが、私はpythonを使ってhtmlを編集する際にいくつかの問題を抱えています。以下は、htmlを格納するために定義した文字列です(長すぎるため、完全ではありません)。私は特定の条件の下でエラーをスローする関数を書くが、私は文字列 "ページ"に行を挿入する方法がわからない。文字列内のこのグループの2があるPython:複数行の文字列に行を挿入するには?
<td class="error">
</td>
注:
page="""
<html>
<head>
<title>Sign up</title>
<style type="text/css">
.label {text-align: right}
.error {color: red}
</style>
</head>
<body>
<h2>Sign up</h2>
<form method="post">
<table>
<tr>
<td class="label">
Username
</td>
<td>
<input type="text" name="username" value="">
</td>
<td class="error">
</td>
</tr>
<tr>
<td class="label">
Password
</td>
<td>
<input type="password" name="password" value="">
</td>
<td class="error">
</td>
</tr>
は、私はこの2行の間の空白で「エラーがあり、」行を挿入したいです。 Pythonを使用して最初のグループに「エラーがあります」と挿入するにはどうすればよいですか?ありがとう。
は、テンプレートエンジンを見ています。例:http://jinja.pocoo.org/ [python string formatting](https://docs.python.org/3/library/stdtypes.html#str.format)を使用してください。 –