这个应用程序昨天工作正常,但现在已经停止了。当我填写表单并点击提交时,我不会像我一直那样重定向,现在它只是刷新页面,在文件上传框中它显示“没有选择文件”。
这是我初始化应用程序的方式..
from flask.ext.uploads import UploadSet, IMAGES, configure_uploads
class Images(object):
images = UploadSet('photos', IMAGES)
def create_app(config_name):
app = Flask(__name__)
app.config.from_object(config[config_name])
config[config_name].init_app(app)
app.config['UPLOADS_DEFAULT_DEST'] = '/var/uploads'
configure_uploads(app, (Images.images,))
我的路线是..
@listings.route('/make_job_listing/', methods=['GET', 'POST'])
#@login_required
def make_job_listing():
form = JobForm()
if form.validate_on_submit():
filename = secure_filename(form.photo.data.filename)
form.photo.data.save('uploads/' + filename)
listing = Listing(title = form.title.data,
description = form.description.data,
location = form.location.data,
photo = 'uploads/' + filename,
listing_type = 'job')
db.session.add(listing)
try:
db.session.commit()
except:
db.session.rollback()
# raise
# finally:
# db.session.close()
return render_template('listings/confirm_listing.html', listing=listing)
return render_template('/listings/make_job_listing.html', form=form)
我的工作表格是......
class JobForm(Form):
''' Job form '''
title = StringField('Enter a title ')
description = TextAreaField('Enter a description')
photo = FileField('image', validators=[
FileRequired(),
FileAllowed(Images.images, 'Images only!')])
location = StringField("where's your nearest city?")
submit = SubmitField('Submit')
我的目录结构是
app/
uploads/
venv/
manage.py