我的应用程序映像上传在localhost上运行良好,但是当我部署到Heroku时,它给了我属性错误和运行时错误。我该如何解决?
按照某些人的建议,我在表单中删除了文件字段中的验证器,但是并不能解决问题
##########
#views.py
def add_post():
form = AddPostForm()
if request.method == 'POST':
if form.validate_on_submit():
filename = images.save(request.files['post_image'])
url = images.url(filename)
new_post = Post( form.post_title.data,
form.post_description.data,
current_user.id, form.is_public.data,
filename, url, form.Share_location.data,
form.home_delivery.data, form.share_date.data,
form.total_slot.data, form.slot_value.data,
form.payable_amount.data, form.no_of_months.data,
form.no_of_weeks.data, form.no_of_days.data,
form.month_sub.data, form.week_sub.data,
form.day__sub.data)
db.session.add(new_post)
db.session.commit()
flash('New shared Item, {}, added!'.format(new_post.post_title),
'success')
return redirect(url_for('posts.public_posts'))
else:
flash_errors(form)
flash('ERROR! Share item was not added.', 'error')
return render_template('add_post.html', title='Add Item', form=form)
#############
#__init__.py
app = Flask(__name__, instance_relative_config=True)
if isfile(join('instance', 'flask_full.cfg')):
app.config.from_pyfile('flask_full.cfg')
else:
app.config.from_pyfile('flask.cfg')
app.config.from_pyfile('flask.cfg')
db = SQLAlchemy(app)
images = UploadSet('images', IMAGES)
configure_uploads(app, images)
#flask.cfg
UPLOADS_DEFAULT_DEST = TOP_LEVEL_DIR + '/project/static/img/'
UPLOADED_IMAGES_URL = 'https://bulkieshare.herokuapp.com/static/img/'
UPLOADED_IMAGES_DEST = TOP_LEVEL_DIR + '/project/static/img/'
UPLOADED_IMAGES_URL = 'https://bulkieshare.herokuapp.com/static/img/'
我想成功将图像文件上传到我的远程数据库,但是我一直从Heroku收到这些错误消息。
#Here is the error message:
[2019-07-12 09:08:40 +0000] [16] [ERROR] Error handling request /add
Traceback (most recent call last):
File "/app/.heroku/python/lib/python3.6/site-packages/flask_uploads.py",
line 327, in config
return current_app.upload_set_config[self.name]
File "/app/.heroku/python/lib/python3.6/site-packages/werkzeug/local.py",
line 347, in __getattr__
return getattr(self._get_current_object(), name)
AttributeError: 'Flask' object has no attribute 'upload_set_config'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/app/.heroku/python/lib/python3.6/site-
packages/gunicorn/workers/sync.py", line 135, in handle
self.handle_request(listener, req, client, addr)
File "/app/.heroku/python/lib/python3.6/site-
packages/gunicorn/workers/sync.py", line 176, in handle_request
respiter = self.wsgi(environ, resp.start_response)
File "/app/.heroku/python/lib/python3.6/site-packages/flask/app.py", line
2309, in __call__
return self.wsgi_app(environ, start_response)
File "/app/.heroku/python/lib/python3.6/site-packages/flask/app.py", line
2295, in wsgi_app
response = self.handle_exception(e)
File "/app/.heroku/python/lib/python3.6/site-packages/flask/app.py", line
1741, in handle_exception
reraise(exc_type, exc_value, tb)
File "/app/.heroku/python/lib/python3.6/site-packages/flask/_compat.py",
line 35, in reraise
raise value
File "/app/.heroku/python/lib/python3.6/site-packages/flask/app.py", line
2292, in wsgi_app
response = self.full_dispatch_request()
File "/app/.heroku/python/lib/python3.6/site-packages/flask/app.py", line
1815, in full_dispatch_request
rv = self.handle_user_exception(e)
File "/app/.heroku/python/lib/python3.6/site-packages/flask/app.py", line
1718, in handle_user_exception
reraise(exc_type, exc_value, tb)
File "/app/.heroku/python/lib/python3.6/site-packages/flask/_compat.py",
line 35, in reraise
raise value
File "/app/.heroku/python/lib/python3.6/site-packages/flask/app.py", line
1813, in full_dispatch_request
rv = self.dispatch_request()
File "/app/.heroku/python/lib/python3.6/site-packages/flask/app.py", line
1799, in dispatch_request
return self.view_functions[rule.endpoint](**req.view_args)
File "/app/.heroku/python/lib/python3.6/site-
packages/flask_login/utils.py", line 261, in decorated_view
return func(*args, **kwargs)
File "/app/project/posts/views.py", line 68, in add_post
filename = images.save(request.files['post_image'])
File "/app/.heroku/python/lib/python3.6/site-packages/flask_uploads.py",
line 414, in save
if not self.file_allowed(storage, basename):
File "/app/.heroku/python/lib/python3.6/site-packages/flask_uploads.py",
line 370, in file_allowed
return self.extension_allowed(extension(basename))
File "/app/.heroku/python/lib/python3.6/site-packages/flask_uploads.py",
line 380, in extension_allowed
return ((ext in self.config.allow) or
File "/app/.heroku/python/lib/python3.6/site-packages/flask_uploads.py",
line 329, in config
raise RuntimeError("cannot access configuration outside request")
RuntimeError: cannot access configuration outside request
10.31.79.212 - - [12/Jul/2019:09:08:40 +0000] "POST /add HTTP/1.1" 500 0
"-" "-"