如何从一个wtform页面上打印多个输出? 所以我在上面创建了一个表单表单.py在
class PostForm(Form):
content = StringField("What's up?", validators=[DataRequired()])
company_name = StringField("Company's Name", validators=[DataRequired()])
job_type = SelectField('Job Type', choices=[('fulltime', 'Full Time'), ('parttime', 'Part Time'), ('contract', 'Contract'), ('internship', 'Internship')])
country = SelectField(
'Country', choices=[('BHR', 'Bahrain'), ('KWT', 'Kuwait'), ('OM', 'Oman'), ('QTR', 'Qatar'), ('SA', 'Saudi Arabia'), ('UAE', 'U.A.E')]
)
job_description = TextAreaField("Job description", validators=[DataRequired()])
responsibilities = TextAreaField("Responsibilities the future employee will have/do.", validators=[DataRequired()])
job_requierments = TextAreaField("Requirements that are needed for the job.", validators=[DataRequired()])
bonus = TextAreaField("Bonus/Extras that an employee can have which makes him a better candidate for the job.", validators=[DataRequired()])
perks = TextAreaField("Perks that the future employee can get by working with you", validators=[DataRequired()])
about_us = TextAreaField("Abous Us (About the employer/Company)", validators=[DataRequired()])
apply_now = TextAreaField("How to apply", validators=[DataRequired()])
email = StringField('Your email', validators=[DataRequired(), Email()])
mob_numb = StringField('Your phone number(s), and please only use numbers!', validators=[DataRequired()])
在我的模型.py我得到了以下结果(请注意,我是在一个在线课程之后这样做的,但是我正在添加和编辑我自己的东西,这就是为什么我不知道如何从一个表单添加多个输出)
^{pr2}$对于我输出的html文件,表单是
{% extends "layout.html" %}
{% block content %}
{% for post in stream %}
<h2><a href="{{ url_for('stream', username=post.user.content) }}"> {{ post.content }} </a></h2>
{% endfor %}
{% endblock %}
我把内容正确地打印出来,效果很好,但是当我尝试添加 在模型中,content=TextField()下的country_name=TextField(),我得到一个错误:
peewee.OperationalError: no such column: t1.company_name
如果我去我的html页面写
{{ form.country_name }}
我得到以下错误
jinja2.exceptions.UndefinedError: 'form' is undefined
如果我用
post.country_name
什么也看不到。在
有什么想法吗?在
编辑:忘记添加我的应用程序副本对于表单
@app.route('/new_post', methods=('GET', 'POST'))
@login_required
def post():
form = forms.PostForm()
if form.validate_on_submit():
models.Post.create(user=g.user.id,
content=form.content.data.strip())
flash("Message posted! Thanks!", "success")
return redirect(url_for('index'))
return render_template('post.html', form=form)
如果在模型.py您还需要更新数据库表。此错误表示模型(在模型.py)与数据库中的表不匹配。在
^{pr2}$在处理您的请求的视图中,您需要在返回中指定一个表单。否则您将无法访问表单。在
这很难判断,因为在你的html中,你已经粘贴了,你正在尝试循环通过“stream”,这是你没有提交的东西与你的html在“post()”方法显示。在
下面的代码希望能给你一个如何在网页中使用表单的想法。在
在应用程序副本在
在页面.html在
相关问题 更多 >
编程相关推荐