problem description
error
AttributeError: "StringField" object has no attribute" content"
the environmental background of the problems and what methods you have tried
the form form renders normally, but an error is reported after filling in the data.
related codes
/ / Please paste the code text below (do not replace the code with pictures)
Form code
class WeiboForm (FlaskForm):
""" """
content = StringField(label=":",
validators=[DataRequired("")],
description="",
render_kw={"required": "required", "class": "form-controal"})
submit = SubmitField(
label="",)
def validate_content(self,field):
""""""
content = field.content
if len(content) < 5:
raise ValidationError("5")
if len(content) > 140:
raise ValidationError("140")
return content
def publish(self,user,db):
""" """
data=self.data
-sharp
weibo=Weibo(
content=data["content"],
user_id=user.id,
is_valid=datetime.new(),
created_at=datetime.new()
)
db.session.add(weibo)
db.session.commit()
return weibo
views Code
@ app.route ("/ home/weibo",methods= ["GET","POST"])
@ login_required
def weibo_publish ():
""" """
form=WeiboForm()
if form.validate_on_submit():
-sharp
form.publish(user=current_user)
-sharp
flash("")
-sharp
return redirect(url_for("index"))
return render_template("/home/weibo.html",form=form)
template templates
{block content}
< div class= "contanier" >
<div class="col-md-6 col-md-offset-3">
<form class="form-weibo" role="form" method="post" action="{{ url_for("weibo_publish") }}">
<div class="form-inner clearfix">
<div class="form-header clearfix">
<span class="pull-left"></span>
<span class="pull-right">21</span>
</div>
{{ form.content }}
<ul class="text-danger">
{% for err in form.content.errors %}
<li>{{ err }}</li>
{% endfor %}
</ul>
<div class="pull-right">
{{ form.csrf_token }}
{{ form.submit }}
</div>
</div>
</form>
</div>
< / div >
{% endblock%}
what result do you expect? What is the error message actually seen?
ask the Great God for help in finding problems?