TypeError:record_club_minutes()缺少2个必需的位置参数:“ purchase”和“ fund”

时间:2019-09-18 04:26:58

标签: python flask

我正在开发一个应用程序,学生可以在其中输入他们的俱乐部数据并为各自的俱乐部创建分钟。现在,尝试将这两个变量从一种形式传递到另一种形式(购买和资金)时遇到了麻烦。它继续给出上面的TypeError。这些变量给出表单中FormField的条目数。该错误最有可能发生在generate_minutes(user_id)中,因为当我在record_club_minutes(user_id,club_id,purchase,fund)中分配了一个固定的整数时,purchase = 0和fund = 0才有效。任何帮助将不胜感激!

routes.py

@login_required
def generate_minutes(user_id):
    user = User.query.get_or_404(user_id)
    # TODO: use the same form
    form = record_club_name_form(user)
    if form.validate_on_submit():
        # send user to the record_club_minutes
            club = form.club_list.data
            purchitems = form.purchaseitems.data
            funditems = form.funditems.data
            return redirect(url_for('clubs.record_club_minutes', user_id=user_id, club_id=club.id, purchase=purchitems, fund=funditems))
    return render_template('record_club_name.html', title='Record', form=form, user=user)

#THERE MAY BE BUGS HERE 
@clubs.route("/record_minutes/<int:user_id>/<int:club_id>/record", methods=['GET', 'POST'])
@login_required
def record_club_minutes(user_id, club_id, purchase, fund):
    user = User.query.get_or_404(user_id)
    club = Club.query.get_or_404(club_id)
    members = club.members
    form = create_club_minutes_form(club, purchase, fund)
    # form.purchaseform.entries = purchase
    # form.fundform.entries = fund
    if form.validate_on_submit():
            minute = Minutes(club_id=club_id, date=form.date.data, time=form.time.data, location=form.location.data, minute=form.notes.data)
            db.session.add(minute)
            for index, field in enumerate(form.attendance):
                if field:
                    attendance = Attendance(student_name=members[index].firstname + members[index].lastname)
                    minute.attendance.append(attendance)    
            db.session.commit()
            flash('Minutes successfully recorded', 'success')
            return redirect(url_for('clubs.view_club_name', user_id=user.id))
    return render_template('record_minutes.html', title='Record', form=form, user=user, club=club, members=members)

此处是上述 record_club_minutes(用户ID,club_id,购买,资金) forms.py

def create_club_minutes_form(club, purchase, fund):
    num_members = len(club.members)
    class ClubMinutesForm(FlaskForm):
        date = DateField('Meeting Date (mm/dd/year)',
            validators=[DataRequired(), DateRange(max = date.today())],
            format = '%m/%d/%Y')
        time = TimeField('Meeting Called to Order at')
        location = StringField('Meeting Place',
            validators=[DataRequired()],
            render_kw={"placeholder":"Room # or Area"})
        attendance = FieldList(BooleanField('Here'),
            min_entries=num_members,
            max_entries=num_members)
        purchaseform = FieldList(FormField(PurchaseOrderForms), 
            min_entries=purchase, 
            max_entries=purchase)
        purchasevote = FormField(MotionForms)
        fundform = FieldList(FormField(FundraiserForms), 
            min_entries=fund, 
            max_entries=fund)
        fundvote = FormField(MotionForms)
        notes = TextAreaField('Overview of Meeting', 
            validators=[DataRequired(), Length(min=10, max=500)])
        submit = SubmitField('Submit')

    return ClubMinutesForm()

跟踪

Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/flask/app.py", line 2463, in __call__
    return self.wsgi_app(environ, start_response)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/flask/app.py", line 2449, in wsgi_app
    response = self.handle_exception(e)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/flask/app.py", line 1866, in handle_exception
    reraise(exc_type, exc_value, tb)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/flask/_compat.py", line 39, in reraise
    raise value
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/flask/app.py", line 2446, in wsgi_app
    response = self.full_dispatch_request()
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/flask/app.py", line 1951, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/flask/app.py", line 1820, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/flask/_compat.py", line 39, in reraise
    raise value
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/flask/app.py", line 1949, in full_dispatch_request
    rv = self.dispatch_request()
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/flask/app.py", line 1935, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/flask_login/utils.py", line 261, in decorated_view
    return func(*args, **kwargs)
TypeError: record_club_minutes() missing 2 required positional arguments: 'purchase' and 'fund'

0 个答案:

没有答案