【发布时间】:2019-09-27 07:58:52
【问题描述】:
我为我的博客页面创建了评论部分,但问题是它在一行中显示名称和评论,我希望这两个都在不同的行中。并且 \n 不工作。
class comments(db.Model):
__tablename__ = 'comment'
id = db.Column(db.Integer,primary_key=True)
name = db.Column(db.Text)
comm = db.Column(db.Text)
def __init__(self,name,comm):
self.name = name
self.comm = comm
def __repr__(self):
return f" Name: {self.name} Comment: {self.comm}"
功能
@app.route('/fat', methods=['GET','POST'])
def fat():
form = AddForm()
if form.validate_on_submit():
name = form.name.data
comm = form.comm.data
newname = comments(name,comm)
db.session.add(newname)
db.session.commit()
return redirect(url_for('fat'))
new = comments.query.all()
return render_template('fat.html',form=form, newnames=new)
下面附上fat.html的代码...................................... ..................................................... ..................................................... …………
</div>
{% block content %}
<div class="post comment">
{% for co in newnames %}
<li>{{co}}</li>
{% endfor %}
</div>
<div class="myform">
<h2>Leave a Comment</h2>
<form method="POST">
{{ form.hidden_tag() }}
<div class="myforms">
<h1 class="myform1"> {{ form.name.label }}</h1>
<h1 class="myform2"> {{ form.name() }} </h1>
</div>
<div class="myformss">
<h1 class="myform3"> {{ form.comm.label }} </h1>
<h1 class="myform4"> {{ form.comm()}}</h1>
</div>
<div class="myformsss">
<h1 class="myform5"> {{ form.submit() }} </h1>
</div>
</form>
</div>
{% endblock %}
【问题讨论】:
标签: html flask flask-sqlalchemy flask-wtforms