Hi everybody, I just uploaded a new branch to github I wish to merge for 0.7. It changes the request handling behavior a great deal for error conditions. It changes the following things: - app.after_request is now no longer called for internal server errors. - app.teardown_request is the official replacement for things that need to be called. And it accomplishes something in return: - much better debugger behavior, give it a try :) the debugger can preserve the request context on errors and this can be controlled. - before_request handlers can abort with exceptions - greatly improved internal control flow - easier to understand. More importantly this will enable me to simplify the new blueprint code I still haven't finished. The downside of this if merged is that you will have to slightly update the code. Also we will have to make sure that the extensions upgrade in time with the release, so there is some work to be done in that regard. Let me know if the branch works for your application, it shouldn't break too much. Make sure to read the upgrading chapter in the documentation to see what it does. If you are curious of the changes, check out the history of the branch on github. https://github.com/mitsuhiko/flask/tree/new-request-dispatching Regards, Armin
Hi Everyone,
I'm very new to flask, and am using flask for my personal website. I've
been expanding on the Flaskr example application for the blog section of my
site.
I have a form, and I want to change the url that form posts to, based on
whether or not there is a post object. so in my template, I have the
following:
{% if post and post.id %}
<form action="{{ url_for('edit_post',post_id=post.id) }}" method=post
class=add-entry>
{% else %}
<form action="{{ url_for('add_post') }}" method=post class=add-entry>
{% endif %}
this feels a bit weird and I am sure there is a better way to do this. is
there a way to reference the current url from jinja2, so I could have
something like:
<form action="{{ get_current_url() }}" method=post class=add-entry>
instead? I had a look through the jinja2 api docs but couldn't find
anything. or, is it better to pass the current url from the controller? if
the latter, is there a way to access the current url from my flask
controller?
thanks in advance for your help, I'm really enjoying using flask so far.
--paul
ig., 2011.eko mairen 29a 16:24(e)an, Paul Sanwald(e)k idatzi zuen: > > is there a way to reference the current url from jinja2, so I could have > something like: > <form action="{{ get_current_url() }}" method=post class=add-entry> > > instead? I had a look through the jinja2 api docs but couldn't find > anything. or, is it better to pass the current url from the controller? > if the latter, is there a way to access the current url from my flask > controller? First of all you should open a new thread for a new topic. Re your question, you can get the current url by using url_for this way: url_for(request.endpoint, **request.view_args)
Hi, On 2011-05-29 4:41 PM, Julen Ruiz Aizpuru wrote: > First of all you should open a new thread for a new topic. This. When I saw the reply in my overview page I was happy to get some feedback on the branch. Was disappointed :) > Re your question, you can get the current url by using url_for this way: > url_for(request.endpoint, **request.view_args) For form submission use <form action="" method="post"> instead which will link to the current page. For everything else there is also {{ request.url }} which does not need to trigger the whole URL building process and also includes query arguments that might have been supplied. Regards, Armin
On 29/05/11 16:41, Julen Ruiz Aizpuru wrote: > ig., 2011.eko mairen 29a 16:24(e)an, Paul Sanwald(e)k idatzi zuen: > > >> is there a way to reference the current url from jinja2, so I could have >> something like: >> <form action="{{ get_current_url() }}" method=post class=add-entry> >> >> instead? I had a look through the jinja2 api docs but couldn't find >> anything. or, is it better to pass the current url from the controller? >> if the latter, is there a way to access the current url from my flask >> controller? > > First of all you should open a new thread for a new topic. > > Re your question, you can get the current url by using url_for this way: > url_for(request.endpoint, **request.view_args) By the way, a <form action=""></form> submits to the current URL. Cheers, -- Daniele
Apologies, I meant to edit the subject. Thanks for answering anyways, wasn't thinking straight this morning. --paul On May 29, 2011, at 11:05 AM, Daniele Nicolodi <daniele@grinta.net> wrote: > On 29/05/11 16:41, Julen Ruiz Aizpuru wrote: >> ig., 2011.eko mairen 29a 16:24(e)an, Paul Sanwald(e)k idatzi zuen: >>> >>> is there a way to reference the current url from jinja2, so I could have >>> something like: >>> <form action="{{ get_current_url() }}" method=post class=add-entry> >>> >>> instead? I had a look through the jinja2 api docs but couldn't find >>> anything. or, is it better to pass the current url from the controller? >>> if the latter, is there a way to access the current url from my flask >>> controller? >> >> First of all you should open a new thread for a new topic. >> >> Re your question, you can get the current url by using url_for this way: >> url_for(request.endpoint, **request.view_args) > > By the way, a <form action=""></form> submits to the current URL. > > Cheers, > -- > Daniele >
On 29/05/11 20:46, Paul Sanwald wrote: > Apologies, I meant to edit the subject. Editing the subject is not enough, the References and In-Reply-To headers would be still wrong. You need to compose a new message. Cheers, -- Daniele
Noted, I'll compose a new message from now on. --paul On May 30, 2011, at 3:49 AM, Daniele Nicolodi <daniele@grinta.net> wrote: > On 29/05/11 20:46, Paul Sanwald wrote: >> Apologies, I meant to edit the subject. > > Editing the subject is not enough, the References and In-Reply-To > headers would be still wrong. You need to compose a new message. > > Cheers, > -- > Daniele