Say I have a Resource that does not do anything but returns the url to the console
from app import api
class StaticFiles(Resource):
def get(self):
return api.url_for(self) # this only provides the resource url
if the request was http://localhost:5000/static code above returns /static I am looking for http://localhost:5000/static
Usually I use requests but there is no request in resources.
I am looking for pretty much the equivalent of request.base_url
request
is a global object which you can access by import
ing request
from flask
:
from flask import request
from app import api
class StaticFiles(Resource):
def get(self):
return(request.base_url)
There are lots of nice alternative formats of the url here, see this answer for more details.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With