Search code examples
flaskflask-admin

Flask-Admin - what to pass in url_for(' ')?


I got an error, that says, that no URL can be build from that parameter inside url_for('').

I passed url_for('admin') but that does not work. What should I pass to get to localhost:5000/admin ?

Thank you


Solution

  • You pass the name of the definition of the route you want to visit.

    For example:

    @app.route('/')
    def index():
        return 'Hello, World!'
    
    ...
    
    @app.route('/some_page')
    def somewhere_else():
        if something_happened:
            redirect(url_for('index'))
        
        return render_template('some_page.html')
    
    

    Or if you are using it inside your HTML:

    <a href="{{ url_for('index') }} ...></a>