Passing Arguments To Modelview Edit Template In Flask-admin
I am trying to learn more about Flask by building a CMS. I am using flask-admin to add the posts, images etc. I have managed to override textarea with ckeditor. But I want to pass
Solution 1:
You have to override the views to change _template_args
.
classTestAdmin(ModelView):
form_overrides = dict(text=forms.CustomTextAreaField)
create_template = 'edit.html'
edit_template = 'edit.html' @expose('/edit/', methods=('GET', 'POST'))defedit_view(self):
self._template_args['foo'] = 'bar'returnsuper(TestAdmin, self).edit_view()
If you want to pass some global value to templates, you can use a context_processor
(http://flask.pocoo.org/docs/templating/#context-processors).
@app.context_processordefinject_paths():
# you will be able to access {{ path1 }} and {{ path2 }} in templatesreturndict(path1='x', path2='y')
Post a Comment for "Passing Arguments To Modelview Edit Template In Flask-admin"