Re: [flask] @app routes for varying urls
- From:
- Alasdair Macmillan
- Date:
- 2010-10-13 @ 11:38
Ah!
I could not find that in the docs. That makes sense but I could still use
an example?
AL
On 13 Oct 2010, at 12:26, danjac354@gmail.com wrote:
> These are query string parameters, so you don't need to map them in
> your route. Just access them in request.args.
>
> On 13 October 2010 12:21, Alasdair Macmillan <al@atomised.coop> wrote:
>> Hi
>>
>> I have a puzzle. How do I create rules for rendering a template for
urls that are generated outside my app but which follow a particular
format. e.g =
>>
>> I'm used to @app.route('/index/')
>>
>> but in my example I need to provide a response to a url that is coming
back like this:
>>
>>
/index/?bucket=myurl&key=myprojects%2Ffinal_logo_screen.jpg&etag=%22aea2817c92dcc269236a0502203aec85%22
>>
>> The url is always the same except the filename 'final_logo_screen.jpg'
and etag '%22aea2817c92dcc269236a0502203aec85%22' parts are different
every time.
>>
>> So I want to render a template to this type of url which I am not in
control of. Does that make sense? However, I do know that if I get this
type of url back that it is legitimate so I just want to accept all urls
of this type and render a single template
>>
>> How would I do this?
>>
>> Kind thanks
>> AL
>>
Re: [flask] @app routes for varying urls
- From:
- Kieran Darcy
- Date:
- 2010-10-13 @ 11:46
*This is your app "test.py"
*
from flask import *
app = Flask(__name__)
@app.route('/index/')
def index():
return render_template('index.html')
if __name__ == '__main__':
app.run('0.0.0.0', debug=True)
*And this is your template "./templates/index.html"
*
<div>Arguments</div>
<ul>
{% for key,value in request.args.items() %}
<li>{{ key }} = {{ value }}</li>
{% endfor %}
</ul>
On 13/10/2010 12:38, Alasdair Macmillan wrote:
> Ah!
>
> I could not find that in the docs. That makes sense but I could still
use an example?
>
> AL
> On 13 Oct 2010, at 12:26, danjac354@gmail.com wrote:
>
Re: [flask] @app routes for varying urls
- From:
- Daniel Neuhäuser
- Date:
- 2010-10-13 @ 12:40
> And this is your template "./templates/index.html"
>
> <div>Arguments</div>
> <ul>
> {% for key,value in request.args.items() %}
> <li>{{ key }} = {{ value }}</li>
> {% endfor %}
> </ul>
`request.args`[1] is basically a `werkzeug.MultiDict`[2], so this may
not show every value. If you use `.lists()` or `.iterlists()` instead
you don't have that problem.
[1]:http://werkzeug.pocoo.org/documentation/0.6.2/wrappers.html#werkzeug.BaseRequest.args
[2]:http://werkzeug.pocoo.org/documentation/0.6.2/datastructures.html#werkzeug.MultiDict
Re: [flask] @app routes for varying urls
- From:
- Kieran Darcy
- Date:
- 2010-10-13 @ 12:50
That's really useful to know. Thanks.
On 13/10/2010 13:40, Daniel Neuhäuser wrote:
> `request.args`[1] is basically a `werkzeug.MultiDict`[2], so this may
> not show every value. If you use `.lists()` or `.iterlists()` instead
> you don't have that problem.
>
>
[1]:http://werkzeug.pocoo.org/documentation/0.6.2/wrappers.html#werkzeug.BaseRequest.args
>
[2]:http://werkzeug.pocoo.org/documentation/0.6.2/datastructures.html#werkzeug.MultiDict
>