我不确定这个问题是在 Django 中还是在 HTML 中,所以我将两者都包括在内。这是我右键单击并选择“查看源代码”时看到的 html:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link href="/static//CSS/postingformstyle.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div style="width:100%;">
<span class="posting_title">Original Work</span>
<form action="" method="post" class="base_form">
<p><label for="id_title">Title:</label> <input type="text" name="title" id="id_title" /></p>
<input type="hidden" name="id">8</input>
<input type="submit" class="posting_button">Post</input>
</form>
</div>
</body>
</html>
当我单击谷歌浏览器中的检查元素时,这就是我得到的,以及似乎呈现的内容。您注意到表单中缺少所有结束标签。
<html xmlns="http://www.w3.org/1999/xhtml"><head>
<meta content="text/html; charset=UTF-8" http-equiv="Content-Type">
<link type="text/css" rel="stylesheet" href="/static//CSS/postingformstyle.css">
</head><body>
<div style="width: 100%;">
<span class="posting_title">Original Work</span>
<form class="base_form" method="post" action="">
<p><label for="id_title">Title:</label> <input type="text" id="id_title" name="title"></p>
<input type="hidden" name="id">8
<input type="submit" class="posting_button">Post
</form>
</div>
</body></html>
这是CSS:
.posting_button {
display:block;
font-size:20px;
width:100%;
}
.posting_title {
text-align:center;
display:block;
color:black;
font-size:30px;
font-family:Arial, Helvetica, sans-serif;
margin: 2px 0 15px 0;
}
.base_form label {
font-size: 17px;
font-family: arial;
font-weight: bold;
display: block;
}
.base_form > p {
margin: 2px 0 5px 0;
}
这是 Django(如果问题存在):
模板:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link href="{{ STATIC_URL }}/CSS/postingformstyle.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div style="width:100%;">
<span class="posting_title">Original Work</span>
<form action="" method="post" class="base_form">
{{ form.as_p }}
<input type="hidden" name="id">{{ id }}</input>
<input type="submit" class="posting_button">Post</input>
</form>
</div>
</body>
</html>
视图.py
def posting_story_ow(request):
if request.method == 'POST':
d = 12
return render_to_response('Posting/Forms/posting_post_ow.html', {'STATIC_URL':STATIC_URL, 'id' : request.GET['id'], 'alertnum': 0, 'form': post_ow})