1

This app was working fine yesterday but now it has stopped. When I complete a form and click on submit I don't get redirected like I have been doing, now it just refreshes the page and in the file upload box it says 'No file chosen'.

This is how I initialize the app..

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,))

My route is..

@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)

My Job form is..

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')

My dir structure is

app/
uploads/
venv/
manage.py

I am redirected to this after I click submit.. enter image description here

0 Answers0