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












1
















This question already has an answer here:




  • Where do I define the domain to be used by url_for() in Flask?

    1 answer



  • How do I get the different parts of a Flask request's url?

    3 answers




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










share|improve this question















marked as duplicate by Dušan Maďar, davidism flask
Users with the  flask badge can single-handedly close flask questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 20 '18 at 13:46


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.




















    1
















    This question already has an answer here:




    • Where do I define the domain to be used by url_for() in Flask?

      1 answer



    • How do I get the different parts of a Flask request's url?

      3 answers




    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










    share|improve this question















    marked as duplicate by Dušan Maďar, davidism flask
    Users with the  flask badge can single-handedly close flask questions as duplicates and reopen them as needed.

    StackExchange.ready(function() {
    if (StackExchange.options.isMobile) return;

    $('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
    var $hover = $(this).addClass('hover-bound'),
    $msg = $hover.siblings('.dupe-hammer-message');

    $hover.hover(
    function() {
    $hover.showInfoMessage('', {
    messageElement: $msg.clone().show(),
    transient: false,
    position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
    dismissable: false,
    relativeToBody: true
    });
    },
    function() {
    StackExchange.helpers.removeMessages();
    }
    );
    });
    });
    Nov 20 '18 at 13:46


    This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.


















      1












      1








      1









      This question already has an answer here:




      • Where do I define the domain to be used by url_for() in Flask?

        1 answer



      • How do I get the different parts of a Flask request's url?

        3 answers




      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










      share|improve this question

















      This question already has an answer here:




      • Where do I define the domain to be used by url_for() in Flask?

        1 answer



      • How do I get the different parts of a Flask request's url?

        3 answers




      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





      This question already has an answer here:




      • Where do I define the domain to be used by url_for() in Flask?

        1 answer



      • How do I get the different parts of a Flask request's url?

        3 answers








      python rest url flask flask-restful






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 20 '18 at 9:46









      Dušan Maďar

      4,37741935




      4,37741935










      asked Nov 20 '18 at 9:15









      Evren BingølEvren Bingøl

      5731727




      5731727




      marked as duplicate by Dušan Maďar, davidism flask
      Users with the  flask badge can single-handedly close flask questions as duplicates and reopen them as needed.

      StackExchange.ready(function() {
      if (StackExchange.options.isMobile) return;

      $('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
      var $hover = $(this).addClass('hover-bound'),
      $msg = $hover.siblings('.dupe-hammer-message');

      $hover.hover(
      function() {
      $hover.showInfoMessage('', {
      messageElement: $msg.clone().show(),
      transient: false,
      position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
      dismissable: false,
      relativeToBody: true
      });
      },
      function() {
      StackExchange.helpers.removeMessages();
      }
      );
      });
      });
      Nov 20 '18 at 13:46


      This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.






      marked as duplicate by Dušan Maďar, davidism flask
      Users with the  flask badge can single-handedly close flask questions as duplicates and reopen them as needed.

      StackExchange.ready(function() {
      if (StackExchange.options.isMobile) return;

      $('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
      var $hover = $(this).addClass('hover-bound'),
      $msg = $hover.siblings('.dupe-hammer-message');

      $hover.hover(
      function() {
      $hover.showInfoMessage('', {
      messageElement: $msg.clone().show(),
      transient: false,
      position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
      dismissable: false,
      relativeToBody: true
      });
      },
      function() {
      StackExchange.helpers.removeMessages();
      }
      );
      });
      });
      Nov 20 '18 at 13:46


      This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.


























          1 Answer
          1






          active

          oldest

          votes


















          1














          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.






          share|improve this answer
























          • ohhh what, Thanks I though request was to be used with only route decorator. What an Idiot I am, I guess it is a thread local object. You wont believe the things I tried.

            – Evren Bingøl
            Nov 20 '18 at 17:13











          • @EvrenBingøl No problem, I don't think this is obvious and I also don't think this is a duplicate question as none of the other answers actually tell you how to get a hold of the request in the first place!

            – Rob Bricheno
            Nov 20 '18 at 18:27


















          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          1














          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.






          share|improve this answer
























          • ohhh what, Thanks I though request was to be used with only route decorator. What an Idiot I am, I guess it is a thread local object. You wont believe the things I tried.

            – Evren Bingøl
            Nov 20 '18 at 17:13











          • @EvrenBingøl No problem, I don't think this is obvious and I also don't think this is a duplicate question as none of the other answers actually tell you how to get a hold of the request in the first place!

            – Rob Bricheno
            Nov 20 '18 at 18:27
















          1














          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.






          share|improve this answer
























          • ohhh what, Thanks I though request was to be used with only route decorator. What an Idiot I am, I guess it is a thread local object. You wont believe the things I tried.

            – Evren Bingøl
            Nov 20 '18 at 17:13











          • @EvrenBingøl No problem, I don't think this is obvious and I also don't think this is a duplicate question as none of the other answers actually tell you how to get a hold of the request in the first place!

            – Rob Bricheno
            Nov 20 '18 at 18:27














          1












          1








          1







          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.






          share|improve this answer













          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.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 20 '18 at 9:47









          Rob BrichenoRob Bricheno

          2,325218




          2,325218













          • ohhh what, Thanks I though request was to be used with only route decorator. What an Idiot I am, I guess it is a thread local object. You wont believe the things I tried.

            – Evren Bingøl
            Nov 20 '18 at 17:13











          • @EvrenBingøl No problem, I don't think this is obvious and I also don't think this is a duplicate question as none of the other answers actually tell you how to get a hold of the request in the first place!

            – Rob Bricheno
            Nov 20 '18 at 18:27



















          • ohhh what, Thanks I though request was to be used with only route decorator. What an Idiot I am, I guess it is a thread local object. You wont believe the things I tried.

            – Evren Bingøl
            Nov 20 '18 at 17:13











          • @EvrenBingøl No problem, I don't think this is obvious and I also don't think this is a duplicate question as none of the other answers actually tell you how to get a hold of the request in the first place!

            – Rob Bricheno
            Nov 20 '18 at 18:27

















          ohhh what, Thanks I though request was to be used with only route decorator. What an Idiot I am, I guess it is a thread local object. You wont believe the things I tried.

          – Evren Bingøl
          Nov 20 '18 at 17:13





          ohhh what, Thanks I though request was to be used with only route decorator. What an Idiot I am, I guess it is a thread local object. You wont believe the things I tried.

          – Evren Bingøl
          Nov 20 '18 at 17:13













          @EvrenBingøl No problem, I don't think this is obvious and I also don't think this is a duplicate question as none of the other answers actually tell you how to get a hold of the request in the first place!

          – Rob Bricheno
          Nov 20 '18 at 18:27





          @EvrenBingøl No problem, I don't think this is obvious and I also don't think this is a duplicate question as none of the other answers actually tell you how to get a hold of the request in the first place!

          – Rob Bricheno
          Nov 20 '18 at 18:27



          Popular posts from this blog

          MongoDB - Not Authorized To Execute Command

          How to fix TextFormField cause rebuild widget in Flutter

          in spring boot 2.1 many test slices are not allowed anymore due to multiple @BootstrapWith