librelist archives

« back to archive

Trouble using url_for outside of templates

Trouble using url_for outside of templates

From:
Slater Victoroff
Date:
2013-08-23 @ 18:38
Hey All,

Sorry if this is a repost, but I just joined this mailing list and I've
been beating my head against a problem with uploading static files for a
while and I figured this was the place to ask. I've already asked a pretty
in-depth SO question and I haven't gotten a response, so I figured this is
the place to go next. I think it makes sense to link to the original SO
question, but let me know if this isn't appropriate.


http://stackoverflow.com/questions/18404137/flask-url-for-incorrectly-links-to-static-pages-outside-of-templates

Many Thanks,

Slater

Re: [flask] Trouble using url_for outside of templates

From:
Joe Angell
Date:
2013-08-23 @ 18:49
url_for takes an argument that is an endpoint (basically
blueprintname.function_name).    http://flask.pocoo.org/docs/api/

It's not clear from your post if 'static' is a proper endpoint.  Another
issue is that save takes a filename, not a url route.  So url_for is not
what you want to be using to generate the filename anyway.  (I could be
wrong about this, I'm not familiar with the file upload api).


On Fri, Aug 23, 2013 at 12:38 PM, Slater Victoroff <
slater.r.victoroff@gmail.com> wrote:

> Hey All,
>
> Sorry if this is a repost, but I just joined this mailing list and I've
> been beating my head against a problem with uploading static files for a
> while and I figured this was the place to ask. I've already asked a pretty
> in-depth SO question and I haven't gotten a response, so I figured this is
> the place to go next. I think it makes sense to link to the original SO
> question, but let me know if this isn't appropriate.
>
>
> 
http://stackoverflow.com/questions/18404137/flask-url-for-incorrectly-links-to-static-pages-outside-of-templates
>
> Many Thanks,
>
> Slater
>



-- 
---------------
Joe Angell
cell: (720) 260-2190

Re: [flask] Trouble using url_for outside of templates

From:
Slater Victoroff
Date:
2013-08-23 @ 19:04
Right now it's returning something along the lines of
"/static/products/filename". It was my understanding (from the flask-s3
docs) that when using flask_s3, it hijacks your url_for method and properly
points it to an S3 bucket. This is what I'm doing for all of my other
static files and it works fine there.

Flask_s3 uses boto under the hood and I would rather not bring that in for
something that I believe should be taken care of pretty simply by flask_s3.
That said, if there's no option for actually getting the flask_s3 version
of url_for working as an upload path as well I would be open to switching
over to boto for that portion.

That said, that might well be the problem. In my mind there was a
one-to-one correspondance between the file system and the static urls, but
in retrospect it's unreasonable to assume that.


On Fri, Aug 23, 2013 at 2:49 PM, Joe Angell <joe.d.angell@gmail.com> wrote:

> url_for takes an argument that is an endpoint (basically
> blueprintname.function_name).    http://flask.pocoo.org/docs/api/
>
> It's not clear from your post if 'static' is a proper endpoint.  Another
> issue is that save takes a filename, not a url route.  So url_for is not
> what you want to be using to generate the filename anyway.  (I could be
> wrong about this, I'm not familiar with the file upload api).
>
>
> On Fri, Aug 23, 2013 at 12:38 PM, Slater Victoroff <
> slater.r.victoroff@gmail.com> wrote:
>
>> Hey All,
>>
>> Sorry if this is a repost, but I just joined this mailing list and I've
>> been beating my head against a problem with uploading static files for a
>> while and I figured this was the place to ask. I've already asked a pretty
>> in-depth SO question and I haven't gotten a response, so I figured this is
>> the place to go next. I think it makes sense to link to the original SO
>> question, but let me know if this isn't appropriate.
>>
>>
>> 
http://stackoverflow.com/questions/18404137/flask-url-for-incorrectly-links-to-static-pages-outside-of-templates
>>
>> Many Thanks,
>>
>> Slater
>>
>
>
>
> --
> ---------------
> Joe Angell
> cell: (720) 260-2190
>

Re: [flask] Trouble using url_for outside of templates

From:
Dorian Hoxha
Date:
2013-08-24 @ 16:01
Well, flask-s3 is for static files. It says it in the title. For
user-uploads you should use boto directly .


On Fri, Aug 23, 2013 at 9:04 PM, Slater Victoroff <
slater.r.victoroff@gmail.com> wrote:

> Right now it's returning something along the lines of
> "/static/products/filename". It was my understanding (from the flask-s3
> docs) that when using flask_s3, it hijacks your url_for method and properly
> points it to an S3 bucket. This is what I'm doing for all of my other
> static files and it works fine there.
>
> Flask_s3 uses boto under the hood and I would rather not bring that in for
> something that I believe should be taken care of pretty simply by flask_s3.
> That said, if there's no option for actually getting the flask_s3 version
> of url_for working as an upload path as well I would be open to switching
> over to boto for that portion.
>
> That said, that might well be the problem. In my mind there was a
> one-to-one correspondance between the file system and the static urls, but
> in retrospect it's unreasonable to assume that.
>
>
> On Fri, Aug 23, 2013 at 2:49 PM, Joe Angell <joe.d.angell@gmail.com>wrote:
>
>> url_for takes an argument that is an endpoint (basically
>> blueprintname.function_name).    http://flask.pocoo.org/docs/api/
>>
>> It's not clear from your post if 'static' is a proper endpoint.  Another
>> issue is that save takes a filename, not a url route.  So url_for is not
>> what you want to be using to generate the filename anyway.  (I could be
>> wrong about this, I'm not familiar with the file upload api).
>>
>>
>> On Fri, Aug 23, 2013 at 12:38 PM, Slater Victoroff <
>> slater.r.victoroff@gmail.com> wrote:
>>
>>> Hey All,
>>>
>>> Sorry if this is a repost, but I just joined this mailing list and I've
>>> been beating my head against a problem with uploading static files for a
>>> while and I figured this was the place to ask. I've already asked a pretty
>>> in-depth SO question and I haven't gotten a response, so I figured this is
>>> the place to go next. I think it makes sense to link to the original SO
>>> question, but let me know if this isn't appropriate.
>>>
>>>
>>> 
http://stackoverflow.com/questions/18404137/flask-url-for-incorrectly-links-to-static-pages-outside-of-templates
>>>
>>> Many Thanks,
>>>
>>> Slater
>>>
>>
>>
>>
>> --
>> ---------------
>> Joe Angell
>> cell: (720) 260-2190
>>
>
>

Re: [flask] Trouble using url_for outside of templates

From:
Harish N
Date:
2013-08-25 @ 13:57
Use url_static and try, I think it helps you

Thanks
On Aug 24, 2013 9:33 PM, "Dorian Hoxha" <dorian.hoxha@gmail.com> wrote:

> Well, flask-s3 is for static files. It says it in the title. For
> user-uploads you should use boto directly .
>
>
> On Fri, Aug 23, 2013 at 9:04 PM, Slater Victoroff <
> slater.r.victoroff@gmail.com> wrote:
>
>> Right now it's returning something along the lines of
>> "/static/products/filename". It was my understanding (from the flask-s3
>> docs) that when using flask_s3, it hijacks your url_for method and properly
>> points it to an S3 bucket. This is what I'm doing for all of my other
>> static files and it works fine there.
>>
>> Flask_s3 uses boto under the hood and I would rather not bring that in
>> for something that I believe should be taken care of pretty simply by
>> flask_s3. That said, if there's no option for actually getting the flask_s3
>> version of url_for working as an upload path as well I would be open to
>> switching over to boto for that portion.
>>
>> That said, that might well be the problem. In my mind there was a
>> one-to-one correspondance between the file system and the static urls, but
>> in retrospect it's unreasonable to assume that.
>>
>>
>> On Fri, Aug 23, 2013 at 2:49 PM, Joe Angell <joe.d.angell@gmail.com>wrote:
>>
>>> url_for takes an argument that is an endpoint (basically
>>> blueprintname.function_name).    http://flask.pocoo.org/docs/api/
>>>
>>> It's not clear from your post if 'static' is a proper endpoint.  Another
>>> issue is that save takes a filename, not a url route.  So url_for is not
>>> what you want to be using to generate the filename anyway.  (I could be
>>> wrong about this, I'm not familiar with the file upload api).
>>>
>>>
>>> On Fri, Aug 23, 2013 at 12:38 PM, Slater Victoroff <
>>> slater.r.victoroff@gmail.com> wrote:
>>>
>>>> Hey All,
>>>>
>>>> Sorry if this is a repost, but I just joined this mailing list and I've
>>>> been beating my head against a problem with uploading static files for a
>>>> while and I figured this was the place to ask. I've already asked a pretty
>>>> in-depth SO question and I haven't gotten a response, so I figured this is
>>>> the place to go next. I think it makes sense to link to the original SO
>>>> question, but let me know if this isn't appropriate.
>>>>
>>>>
>>>> 
http://stackoverflow.com/questions/18404137/flask-url-for-incorrectly-links-to-static-pages-outside-of-templates
>>>>
>>>> Many Thanks,
>>>>
>>>> Slater
>>>>
>>>
>>>
>>>
>>> --
>>> ---------------
>>> Joe Angell
>>> cell: (720) 260-2190
>>>
>>
>>
>

Re: [flask] Trouble using url_for outside of templates

From:
Joshua Ma
Date:
2013-08-23 @ 18:48
What exactly is url_for returning? It looks like you're trying to save an
image to a URL. The save function is expecting a filesystem path - it can't
"write" to what I'm assuming is an S3 URL.

If you want to upload to S3, you might want to look into boto and the
Key.set_content_from_file function: http://boto.s3.amazonaws.com/s3_tut.html

- Josh


On Fri, Aug 23, 2013 at 11:38 AM, Slater Victoroff <
slater.r.victoroff@gmail.com> wrote:

> Hey All,
>
> Sorry if this is a repost, but I just joined this mailing list and I've
> been beating my head against a problem with uploading static files for a
> while and I figured this was the place to ask. I've already asked a pretty
> in-depth SO question and I haven't gotten a response, so I figured this is
> the place to go next. I think it makes sense to link to the original SO
> question, but let me know if this isn't appropriate.
>
>
> 
http://stackoverflow.com/questions/18404137/flask-url-for-incorrectly-links-to-static-pages-outside-of-templates
>
> Many Thanks,
>
> Slater
>