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











up vote
1
down vote

favorite













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 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.



















    up vote
    1
    down vote

    favorite













    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 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.

















      up vote
      1
      down vote

      favorite









      up vote
      1
      down vote

      favorite












      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 at 9:46









      Dušan Maďar

      4,21241935




      4,21241935










      asked Nov 20 at 9:15









      Evren Bingøl

      5581727




      5581727




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

















          up vote
          1
          down vote













          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 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 at 18:27


















          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          up vote
          1
          down vote













          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 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 at 18:27















          up vote
          1
          down vote













          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 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 at 18:27













          up vote
          1
          down vote










          up vote
          1
          down vote









          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 at 9:47









          Rob Bricheno

          2,280218




          2,280218












          • 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 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 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 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 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 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 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 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 at 18:27



          Popular posts from this blog

          404 Error Contact Form 7 ajax form submitting

          How to know if a Active Directory user can login interactively

          Refactoring coordinates for Minecraft Pi buildings written in Python