1

该应用程序昨天运行良好,但现在已停止。当我完成表单并单击提交时,我不会像以前那样被重定向,现在它只是刷新页面并在文件上传框中显示“未选择文件”。

这就是我初始化应用程序的方式..

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

单击提交后,我被重定向到此.. 在此处输入图像描述

4

0 回答 0