class AdminPageForm(Form): content_type_choices = [ ("text", "Text"), ("markdown", "Markdown"), ("raw", "Raw") ] pages = [] parent_pages = [] def __init__(self, pages): if pages: self.pages = pages else: self.pages = [] self.parent_pages = [("", gettext("(None, this will be a top page)"))] for page in self.pages: self.parent_pages.append( (str(page.id), "%s (%s)" % (page.path, page.title))) path = TextField(gettext("Path"), validators = [DataRequired()]) title_da = TextField(gettext("Title (Danish)"), validators = [DataRequired()]) title_en = TextField(gettext("Title (English)"), default="") ... @app.route("/admin/pages/edit/", methods=["GET", "POST"]) @app.route("/admin/pages/edit/", methods=["GET", "POST"]) @login_required def admin_edit_page(page_id=None): app.logger.debug("admin_edit_page") pages = Page.query.all() form = AdminPageForm(pages=pages) if form.validate_on_submit(): app.logger.debug("SUBMITTED") if page_id: app.logger.debug("GOT PAGE ID --> EXISTING PAGE") page= db.session.query(Page).filter(Page.id==page_id).first() else: app.logger.debug("NOT PAGE ID --> NEW PAGE") page = Page() page.path = form.path.data ....