如何允许POST方法在flask-admin继承基视图?



我已经扩展了flask-admin的BaseView来创建一个产品视图,在那里我可以将产品添加到我的数据库。但是在提交的时候。它显示这个方法是不允许的

class ProductsView(BaseView):
@expose('/')
def add_products(self):
form = AddProducts()
if request.method == 'POST':
print("Here")
name = form.name.data
price = form.price.data
discount = form.price.data
brand = form.brand.data
description = form.description.data
image = photos.save(request.files.get('image'))
add_product = Products(
name=name, price=price,
discount=discount, brand=brand,
desc=description,
image_1=image
)
db.session.add(add_product)
flash(f"{name} is added to the database successfully!!!", "success")
db.session.commit()
return redirect(url_for('home'))
return self.render(template='products/addproducts.html', title="Add Products", form=form)
admin = Admin(app, name='Ekart Admin', template_mode='bootstrap3')
admin.add_view(ModelView(Products, db.session))
admin.add_view(ModelView(User, db.session))
admin.add_view(ProductsView(name='Add Products(Local)'))

这里,我只需要在add_product视图中允许post方法。

你可以试试吗?@expose ('/', medthods =['文章'])

最新更新