在烧瓶中显示上传的图像,而不是在静态文件夹中

时间:2018-11-10 16:59:22

标签: twitter-bootstrap image flask jinja2

Application structure

如何在Flask中显示上载的图像,我在database中存储路径,并使用Flask-Uploads将图像作为附件图像和我的上载文件夹uploaddir上载到文件夹中与应用程序文件夹,那是我想要的
app.py

photos = UploadSet('photos', IMAGES)
    def create_app():
        app = Flask(__name__, static_folder='templates/static', template_folder='templates')
        app.config.from_object(Config)
        app.config['UPLOADED_PHOTOS_DEST']

和route.py保存图像

filename = photos.save(request.files['stud_img'], 'student/{}'.format(student.code))
            file_desc = _('Personal Image')
            student_photo = UploadFile(file_name=filename, file_desc=file_desc, student_id=student.id)

和route.py用于显示

@student_bp.route('/view/<int:student_id>', methods=['GET' ,'POST'])
def view(student_id):
    student = Student.query.get(student_id)
    img =student.uploadfiles.filter(UploadFile.file_desc == 'pi').first()
    return render_template('view_student.html', title=_('View Student'), student_id=student_id, student=student, img=img, )

和我的模板

 <div id="crop-avatar">
  <!-- Current avatar -->
    <img class="img-responsive avatar-view" src="{{ img.file_name }}"
                   alt="Avatar" title="Change the avatar">
  </div>

img.file_name是正确的,并获得了string的名称,但我尝试手动放置未显示的图像路径。

0 个答案:

没有答案