librelist archives

« back to archive

Having trouble to show uploaded image

Having trouble to show uploaded image

From:
Huseyin Inciler
Date:
2015-02-05 @ 09:05
I want to show my uploaded image on my page but I couldn’t success it. I 
have this error:


werkzeug.routing.BuildError
BuildError: ('uploaded_file', {'filename': u'user/user-1/scan.jpeg'}, None)

 This is my code to show image on my page:

UPLOAD_FOLDER = “upload"

@app.route('/uploads/<filename>')
def uploaded_file(filename):    
    return send_from_directory(app.config['UPLOAD_FOLDER'], filename)

class UserJsonDataController(BaseController, MethodView):
    def __init__(self):
        super(UserJsonDataController, self).__init__()

    def get(self):
        json = {}
        users = User.select()
        a = []
        for user in users:
            obj = {
                "username":user.username,
                "email":user.email,
                "display_name":user.display_name,
                #url_for("uploaded_file", filename = user.user_avatar)
                "user_avatar": url_for("uploaded_file", filename = 
user.user_avatar)
                # "user_avatar":user.user_avatar
            }
            a.append(obj)
        json["rows"] = a

        return flask.jsonify(json)

module.add_url_rule('/index/show', 
view_func=UserJsonDataController.as_view('show’))

and my html page is:

<div id="user-list">
    <div id="grid"></div>
</div>

 <script>
    $(document).ready(function () {
        $("#grid").kendoGrid({
            dataSource: {
                transport: {
                    read: {
                        url: '{{ url_for("user_admin.show") }}',
                        dataType: "json"
                    }
                },
                pageSize: 20,
                schema: {
                    data: "rows"
                  }
            },
            height: 550,
            sortable: true,
            pageable: {
                refresh: true,
                pageSizes: true,
                buttonCount: 5
            },
            columns: [{
                field: "user_avatar",
                title: "Profil",
                template: "<img src='/#=user_avatar #' /> "    
            }, {
                field: "username",
                title: "User Name"    
            }, {
                field: "email",
                title: "Email"
            }, {
                field: "display_name",
                title: "Name"
            }]
        });
    });
</script>