Search code examples
pythonflaskeve

Is there url_for() in eve?


We know in Flask, there is url_for() for endpoint, like url_for('edit', _external=True) I what to ask what's the best practice in python eve ?


Solution

  • Since eve is Flask application url_for works well. e.g.

    $ python manage.py shell
    In [1]: from flask import url_for
    
    In [2]: url_for('home')
    Out[2]: '/'
    
    In [3]: url_for('users|resource')
    Out[3]: '/users'
    

    In the above example users is one of the collection. There are few more that would work conditionally like 'users|item_lookup, users|item_post_override etc. (They don't work on my setup due to my own settings.py file)

    To learn more, have a look at the flaskapp.py file, and search for add_url_rule