pommicket
pommicket

Reputation: 942

Fix absolute urls in Flask apache application

I wrote a web application in Flask, then I decided to use Apache to deploy it:

<VirtualHost *:80>
    WSGIScriptAlias /app /var/www/flask-app/flask-app.py
    <Directory /var/www/flask-app>
        Require all granted
    </Directory>
</VirtualHost>

But now, links such as:

<a href='/login'>Sign in</a>

Go to /login instead of /app/login. Is there any way to fix this, without changing all of the URLs?

Upvotes: 1

Views: 454

Answers (1)

Allie Fitter
Allie Fitter

Reputation: 1807

As PJ Santoro said you should be using url_for. This takes the ambiguity out of routes.

<a href='{{ url_for('route_function_name') }}'>Sign in</a>

Where:

@routes.route('/login', methods=['GET'])
def route_function_name():
    return 'blah'

Upvotes: 1

Related Questions