Search code examples
pythonflask-bootstrapflask-nav

How to replace brand text with an image in flask-nav


I've got a nav-bar showing in my flask-bootstrap application by importing flask-nav and using the following:

@nav.navigation()
def mynavbar():
    return Navbar(
        'MyCompany',
        View('Main', 'index'),
        View('Config', 'config'),
        View('Help', 'help')
    )

But I can't find for the life of me how to swap the text "MyCompany" for an image, e.g. img/mylogo.png . Can anyone tell me how?


Solution

  • I'm not entirely happy with this as I think the solution should be a lot simpler, but this works:

    import dominate
    from dominate.tags import img
    
    nav = Nav()
    branding = img(src='static/img/myimage.png')
    
    @nav.navigation()
    def mynavbar():
        return Navbar(
        branding,
        View('Main', 'index'),
        View('Config', 'config'),
        View('Help', 'help')
    )
    
    
    nav.init_app(app)
    

    The problem with just putting the html string in, for example <img src="myimage.png">, was that the string was printed rather than being interpreted as an element that should be displayed. The dominate package seems to overcome this.