Search code examples
pythonhtmlflaskflask-sqlalchemyflask-admin

How do I run html script in flask-admin panel columns?


I have added a property to Quiz model that returns html code.

@property
def create_questions(self):
    if self.no_of_questions_created == self.quiz_capacity:
        return '<a href=""><button class="btn btn-primary">Edit Questions</button></a>'
    elif self.no_of_questions_created < self.quiz_capacity:
        return '<a href=""><button class="btn btn-primary">Add more Questions</button></a>'
    elif self.no_of_questions_created == None:
        return '<a href=""><button class="btn btn-primary">Add Questions</button></a>'

I expected a bootstrap button to be displayed in column section, but I got plain html text. table view link

How can I get the desired button here?


Solution

  • I figured out myself using Markup() solved the problem.

    from flask import Markup
    
    def create_questions(self):
        if self.no_of_questions_created == self.quiz_capacity:
            return Markup('<a href=""><button class="btn btn-primary">Edit Questions</button></a>')
    

    table view