librelist archives

« back to archive

Paths

Paths

From:
Wawrzek Niewodniczanski
Date:
2013-03-08 @ 21:27
Hello,

First of all  big thank you for the work on Flask. It's very solid
product and I have a lot of joy to work with it.

Recently I hit two small issue realated to path.

1)
In my application I made  pages with a path
"/myapp/customer/<local>/<id>". Inside the template I have following
line:

    <a href="volume/{{ volume_name }}"><div class="link">{{
volume_name }}</div></a>

which obviously lead to:
 /myapp/customer/<local>/<id>/volume/{{volume_name}}

the problem is I would like have link to:
/myapp/volume/{{volume_name}}

How should I set url in href to point to application root dir?


2)
I'm using Apache with mod_wsgi for hosting my application. I have
following file in /etc/httpd/conf.d:

WSGIDaemonProcess myapp threads=5
WSGIScriptAlias /myapp /opt/myapp/main.wsgi

<Directory /myapp/>
    WSGIProcessGroup myapp
    WSGIApplicationGroup %{GLOBAL}
    Order deny,allow
    Allow from all
</Directory>

Now, you can reach page with URL with and without trailing slash

http://myhost/myapp

and

http://myhost/myapp/

But only second provides proper further links. It's not unexpected,
and think it's desire behaviour, but I wonder what the easiest way to
redirect
people from /myapp to /myapp/.

Thanks,
Wawrzek

--
Dr  Wawrzyniec Niewodniczański    or Wawrzek for short
  PhD in Quantum Chemistry  & MSc in Molecular Engineering
   WWW: http://wawrzek.name E-MAIL: jobs@wawrzek.name
      Linux User #177124

Re: [flask] Paths

From:
dorian i
Date:
2013-03-08 @ 21:33
1. It is usually better to put create links using {{

url_for('application_name.function_where_you_want_to_point',argument1=value,argument2=value)
}}

Can't help you on the second.

On Fri, Mar 8, 2013 at 10:27 PM, Wawrzek Niewodniczanski
<main@wawrzek.name>wrote:

> Hello,
>
> First of all  big thank you for the work on Flask. It's very solid
> product and I have a lot of joy to work with it.
>
> Recently I hit two small issue realated to path.
>
> 1)
> In my application I made  pages with a path
> "/myapp/customer/<local>/<id>". Inside the template I have following
> line:
>
>     <a href="volume/{{ volume_name }}"><div class="link">{{
> volume_name }}</div></a>
>
> which obviously lead to:
>  /myapp/customer/<local>/<id>/volume/{{volume_name}}
>
> the problem is I would like have link to:
> /myapp/volume/{{volume_name}}
>
> How should I set url in href to point to application root dir?
>
>
> 2)
> I'm using Apache with mod_wsgi for hosting my application. I have
> following file in /etc/httpd/conf.d:
>
> WSGIDaemonProcess myapp threads=5
> WSGIScriptAlias /myapp /opt/myapp/main.wsgi
>
> <Directory /myapp/>
>     WSGIProcessGroup myapp
>     WSGIApplicationGroup %{GLOBAL}
>     Order deny,allow
>     Allow from all
> </Directory>
>
> Now, you can reach page with URL with and without trailing slash
>
> http://myhost/myapp
>
> and
>
> http://myhost/myapp/
>
> But only second provides proper further links. It's not unexpected,
> and think it's desire behaviour, but I wonder what the easiest way to
> redirect
> people from /myapp to /myapp/.
>
> Thanks,
> Wawrzek
>
> --
> Dr  Wawrzyniec Niewodniczański    or Wawrzek for short
>   PhD in Quantum Chemistry  & MSc in Molecular Engineering
>    WWW: http://wawrzek.name E-MAIL: jobs@wawrzek.name
>       Linux User #177124
>

Re: [flask] Paths

From:
Joe Esposito
Date:
2013-03-08 @ 21:49
For (2), simply route your views with a trailing slash, like so

@app.route('/my-path/')

Now when you visit /my-path, you'll be redirected to /my-path/
automatically.
'url_for' will also properly include trailing slashes for these routes.

On Fri, Mar 8, 2013 at 4:33 PM, dorian i <dorian.hoxha@gmail.com> wrote:

> 1. It is usually better to put create links using {{
> 
url_for('application_name.function_where_you_want_to_point',argument1=value,argument2=value)
> }}
>
> Can't help you on the second.
>
>
> On Fri, Mar 8, 2013 at 10:27 PM, Wawrzek Niewodniczanski <
> main@wawrzek.name> wrote:
>
>> Hello,
>>
>> First of all  big thank you for the work on Flask. It's very solid
>> product and I have a lot of joy to work with it.
>>
>> Recently I hit two small issue realated to path.
>>
>> 1)
>> In my application I made  pages with a path
>> "/myapp/customer/<local>/<id>". Inside the template I have following
>> line:
>>
>>     <a href="volume/{{ volume_name }}"><div class="link">{{
>> volume_name }}</div></a>
>>
>> which obviously lead to:
>>  /myapp/customer/<local>/<id>/volume/{{volume_name}}
>>
>> the problem is I would like have link to:
>> /myapp/volume/{{volume_name}}
>>
>> How should I set url in href to point to application root dir?
>>
>>
>> 2)
>> I'm using Apache with mod_wsgi for hosting my application. I have
>> following file in /etc/httpd/conf.d:
>>
>> WSGIDaemonProcess myapp threads=5
>> WSGIScriptAlias /myapp /opt/myapp/main.wsgi
>>
>> <Directory /myapp/>
>>     WSGIProcessGroup myapp
>>     WSGIApplicationGroup %{GLOBAL}
>>     Order deny,allow
>>     Allow from all
>> </Directory>
>>
>> Now, you can reach page with URL with and without trailing slash
>>
>> http://myhost/myapp
>>
>> and
>>
>> http://myhost/myapp/
>>
>> But only second provides proper further links. It's not unexpected,
>> and think it's desire behaviour, but I wonder what the easiest way to
>> redirect
>> people from /myapp to /myapp/.
>>
>> Thanks,
>> Wawrzek
>>
>> --
>> Dr  Wawrzyniec Niewodniczański    or Wawrzek for short
>>   PhD in Quantum Chemistry  & MSc in Molecular Engineering
>>    WWW: http://wawrzek.name E-MAIL: jobs@wawrzek.name
>>       Linux User #177124
>>
>
>

Re: [flask] Paths

From:
Alex Ogier
Date:
2013-03-08 @ 22:05
On Fri, Mar 8, 2013 at 4:49 PM, Joe Esposito <espo58@gmail.com> wrote:

> @app.route('/my-path/')


For a WSGI script at /myapp, this will not work. The above will not work
for the root path, that is the view with @app.route('/'). This is a known
issue: https://github.com/mitsuhiko/flask/issues/169

You have two options: one is to configure Apache to do the redirect from
/myapp to /myapp/ (for example with mod_rewrite). The other option is to
use one of the Python middleware fixes in the comments on the github issue
I linked above that does the redirection in your application.

Best,
Alex Ogier

Re: [flask] Paths

From:
Wawrzek Niewodniczanski
Date:
2013-03-11 @ 22:26
On 8 March 2013 22:05, Alex Ogier <alex.ogier@gmail.com> wrote:
> On Fri, Mar 8, 2013 at 4:49 PM, Joe Esposito <espo58@gmail.com> wrote:
>>
>> @app.route('/my-path/')
>
>
> For a WSGI script at /myapp, this will not work. The above will not work for
> the root path, that is the view with @app.route('/'). This is a known issue:
> https://github.com/mitsuhiko/flask/issues/169
>

Thanks for conforming my thoughts.

Wawrzek
-- 
Dr  Wawrzyniec Niewodniczański    or Wawrzek for short
  PhD in Quantum Chemistry  & MSc in Molecular Engineering
   WWW: http://wawrzek.name E-MAIL: jobs@wawrzek.name
      Linux User #177124

Re: [flask] Paths

From:
Wawrzek Niewodniczanski
Date:
2013-03-11 @ 22:12
On 8 March 2013 21:33, dorian i <dorian.hoxha@gmail.com> wrote:
> 1. It is usually better to put create links using {{
> 
url_for('application_name.function_where_you_want_to_point',argument1=value,argument2=value)
> }}
>

Thanks for this suggestion. It seems not to work, but it might be
because of blueprint I use.

In my main file I have:

app = Flask(__name__)
...
app.register_blueprint(volume.vol)


in blueprint

vol = Blueprint('volume', __name__)
...

@vol.route('/volume/')
@vol.route('/volume/<volume_name>')
def volume_page(volume_name=None):


So what should I put in url_for? This is in template for other blueprint.

Thanks,
Wawrzek


--
Dr  Wawrzyniec Niewodniczański    or Wawrzek for short
  PhD in Quantum Chemistry  & MSc in Molecular Engineering
   WWW: http://wawrzek.name E-MAIL: jobs@wawrzek.name
      Linux User #177124