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,41442035




      4,41442035










      asked Nov 20 '18 at 9:15









      Evren BingølEvren Bingøl

      5901727




      5901727




      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,375318




          2,375318













          • 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

          How to pass form data using jquery Ajax to insert data in database?

          National Museum of Racing and Hall of Fame

          Guess what letter conforming each word