如何從一個單一的平臺獲得打印在頁面上的多個輸出? 所以我對forms.pywtforms flask的多個輸出
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 %}
我得到的內容打印OU牛逼正確,它的偉大工程,但是當我試圖在內容添加例如 COUNTRY_NAME =文本字段()=文本字段()的模型我得到一個錯誤:
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)
得到它的工作與您的幫助。謝謝!我做的是我添加了ex:'company_name = TextField()'在我的models.py和我的app.py我在post()下添加了'company_name = form.company_name.data.strip()'並且使它工作! – qasimalbaqali 2015-04-01 11:32:18