Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to get the full url in flask_restful from a resource [duplicate]

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

like image 740
Evren Bingøl Avatar asked Nov 20 '18 09:11

Evren Bingøl


1 Answers

request is a global object which you can access by importing 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.

like image 155
Rob Bricheno Avatar answered Nov 15 '22 03:11

Rob Bricheno