Why not fill it in Flask-Admin?

Here is an example of how I do it.
class MyBase(BaseView):
 def __init__(self,def_view,**kwargs):
 self.default_view = def_view
 super(MyBase, self).__init__(**kwargs)

class AddFarmerForm(wtf.Form):
 fileName = FileField()


class MyView(MyBase):
@expose('/',methods=('GET','POST'))
 def index(self):
 form = AddFarmerForm()
 if form.validate_on_submit():
 file_name = secure_filename(form.fileName.file.filename)
form.fileName.file.save('app/static/'+file_name)
 return self.render('admin/index.html',form=form)


And this is a pattern where everything happens.
{% block head_meta %}
{% endblock %}
{% extends 'admin/master.html' %}
{% import 'admin/lib.html' as lib with context %}
{% block body %}
 <form method="post" enctype="multipart/form-data">
 {{ form.fileName() }}
 <input type="submit">
</form>
{% endblock %}
September 26th 19 at 06:07
0 answer

Find more questions by tags Python