Как мне распечатать несколько выходных данных на странице из одной формы wtform? Итак, у меня есть форма, созданная на forms.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()])
и в моем models.py я получил следующее (обратите внимание, что я делаю это после онлайн-курса, но я добавляю и редактирую свои собственные материалы, поэтому я не знаю, как добавить несколько выходов из одной формы)
class Post(Model):
timestamp = DateTimeField(default=datetime.datetime.now)
user = ForeignKeyField(
rel_model=User,
related_name='posts'
)
content = TextField()
а для моего 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 %}
Я правильно распечатываю контент, и он отлично работает, но когда я пытаюсь добавить, например, country_name = TextField () под content = TextField () в модели, я получаю сообщение об ошибке:
peewee.OperationalError: no such column: t1.company_name
и если я перейду на свою html-страницу и напишу
{{ form.country_name }}
Я получаю следующую ошибку
jinja2.exceptions.UndefinedError: 'form' is undefined
и если я использую
post.country_name
ничего не показывает.
Любые идеи?
РЕДАКТИРОВАТЬ: забыл добавить мой app.py для формы
@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)