librelist archives

« back to archive

How to dynamically generate urls for requst outside of jinja?

How to dynamically generate urls for requst outside of jinja?

From:
James Anderson
Date:
2012-10-18 @ 21:31
Hello,

I have an app that uses Flask-Mail to generate notifications. I've built a
method that generates a hash and when a user goes to a url appended by that
hash (ex: www.site.com/checkhash/qY20djl1L1EUHObr9Y*) *they are then able
to confirm an email account for their account on the website. Because I'm
doing this entirely inside of the flask application, I'm not familiar with
the type of filters available. I tried storing url_for('method') in  a
variable, and then appending my hash to it, but flask bombs out on me. The
purpose is to be able to generate a url for an email without it being
hardcoded for the domain the site is being hosted on.

Thank in advance,

James

Re: [flask] How to dynamically generate urls for requst outside of jinja?

From:
Simon Sapin
Date:
2012-10-19 @ 05:25
Le 18/10/2012 23:31, James Anderson a écrit :
> I tried storing url_for('method') in  a variable, and then appending my
> hash to it, but flask bombs out on me.

Full traceback please.

Re: [flask] How to dynamically generate urls for requst outside of jinja?

From:
James Anderson
Date:
2012-10-19 @ 16:39
I resolved the issue. I wanted to share in case anyone else was trying to
generate external URLs the same way. Here was my solution. I ended up
needing _external as well as to define my passed variable instead of just
appending to the base URL using a string.

my method structure is like this:

@app.route('/user/verify_account/<confHash>', methods=['GET'])
def confirm_hash(confHash):

so I use this to generate my url for sending via flask-mail.

confURL = url_for('confirm_hash', confHash = confHash, _external=True)

On Thu, Oct 18, 2012 at 10:25 PM, Simon Sapin <simon.sapin@exyr.org> wrote:

> Le 18/10/2012 23:31, James Anderson a écrit :
> > I tried storing url_for('method') in  a variable, and then appending my
> > hash to it, but flask bombs out on me.
>
> Full traceback please.
>