stewartpark / Flask-JSGlue

Flask-JSGlue helps hook up your Flask application nicely with the front end.
80 stars 39 forks source link

Getting an absolute url #1

Closed janicejl closed 9 years ago

janicejl commented 9 years ago

Thanks for all your work with js_glue, it has been very helpful.

I am currently trying to get an absolute url for one of my routes. I understand that this can be done by passing _external=True to the url_for function in Flask. Is this possible to do with js_glue?

I have tried the follow: Flask.url_for('fn_name', { '_external': 'True' }) -- string of Python true. Flask.url_for('fn_name', { '_external': true }) -- javascript true

Neither of them have managed to get the absolute url for the route.

Would you be able to advise if this is possible with js_glue, and if so, how do I get the absolute url?

Thanks in advance.

stewartpark commented 9 years ago

Hi Janice,

JSGlue is a client-side reimplementation of url_for therefore the option you were trying to use was unsupported until now.

But the most recent version of Flask-JSGlue now supports those options that start with _(_external, _scheme, _anchor).

Even though it can be done with a dirty way(location.origin + Flask.url_for(...)), I thought making it prettier is the purpose of this extension so I just implemented the options.

Go to your terminal and upgrade your Flask-JSGlue by:

$ pip install --upgrade Flask-JSGlue 

Now the following works as intended:

Flask.url_for('fn_name', { '_external': true })

Along with this, I have updated the documentation as well, so please check.

Thanks for the input.