得到了一个AttributeError:对象没有属性“name”,但这是一个类,而不是一个属性

时间:2013-11-26 12:28:08

标签: python flask

所以我被困在这个烧瓶应用程序中,我还没有很好地使用Python,所以我想这将是一个非常简单的错误

    @app.route('/add-item/', methods=['GET', 'POST'])
    @login_required
    def add_item():
        form = AddItemForm()
        if form.validate_on_submit():
            name = form.item_name.data
            category_name = form.category_name.data
            print category_name
            kind = form.feedback.data
            text = form.review.data
            image_name = secure_filename(form.image.data.filename)
            print(image_name)
            image_data = form.image.data
            filepath = os.path.join(app.config['UPLOAD_FOLDER'], image_name)
            image_data.save(filepath.encode('utf-8'))
            itm = item.Item(name, g.user, category_name)
            rev = review.Review(text, g.user, kind)
            vow = vote.Vote(itm.id, g.user.id, VOTE_UP) #THIS LINE SEEMS TO TRIGGER THE ERROR
            pht = photo.Photo(filepath, g.user, itm.id)
            db.insert_review(rev)
            db.insert_vote(vow)
            db.insert_photo(pht)
            itm.reviews.append(rev)
            itm.votes.append(vow)
            itm.photos.append(pht)
            db.insert_item(itm)
            return render_template('item-added.html', title="item added successfully")
        else:
            return render_template('add-item.html', title="new item", form=form)

我收到此错误:

127.0.0.1 - - [26/Nov/2013 13:11:17] "POST /add-item/ HTTP/1.1" 500 -
Traceback (most recent call last):
  File "C:\Python27\lib\site-packages\flask\app.py", line 1836, in __call__
    return self.wsgi_app(environ, start_response)
  File "C:\Python27\lib\site-packages\flask\app.py", line 1820, in wsgi_app
    response = self.make_response(self.handle_exception(e))
  File "C:\Python27\lib\site-packages\flask\app.py", line 1403, in handle_exception
    reraise(exc_type, exc_value, tb)
  File "C:\Python27\lib\site-packages\flask\app.py", line 1817, in wsgi_app
    response = self.full_dispatch_request()
  File "C:\Python27\lib\site-packages\flask\app.py", line 1477, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "C:\Python27\lib\site-packages\flask\app.py", line 1381, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "C:\Python27\lib\site-packages\flask\app.py", line 1475, in full_dispatch_request
    rv = self.dispatch_request()
  File "C:\Python27\lib\site-packages\flask\app.py", line 1461, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "C:\Python27\lib\site-packages\flask_login.py", line 658, in decorated_view
    return func(*args, **kwargs)
  File "C:\Users\Luca\PycharmProjects\byb\byb.py", line 92, in add_item
    vow = vote.Vote(itm.id, g.user.id, VOTE_UP)
AttributeError: 'function' object has no attribute 'Vote'

我的问题是我无法理解为什么会出现这样的错误:投票是一个文件(vote.py),投票是一个类,我很困惑,任何提示(我也不确定是否我格式正确,如果标题有意义的话)

0 个答案:

没有答案