Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

pyramid: get application absolute url

Is there any way to get pyramid absolute application url in main() function? I want to add it into global settings, so it could be called every where(in templates and js files). In pyramid documents there is some functions would help, but all of them need a request object and must call in a view. Thanks.

like image 545
Mehdi Seifi Avatar asked Jun 14 '11 18:06

Mehdi Seifi


2 Answers

Pyramid (like most WSGI applications) can be mounted on any domain and url prefix. Thus the application itself doesn't actually know what urls it is responsible for unless you code that into your application specifically (an INI setting, for example).

This is why request.application_url exists... because the application_url could be different per request based on how many different domains and url prefixes you have that are proxying requests to your application.

like image 56
Michael Merickel Avatar answered Oct 23 '22 23:10

Michael Merickel


I just get the full route for my index route, 'home' in my case:

I set this in my main wrapper mako template so that all of my JS calls can reference it to build a proper path for ajax calls/etc

    <script type="text/javascript" charset="utf-8">
        <%
            app_url = request.route_url('home').rstrip('/')
        %>
        APP_URL = '${app_url}';
    </script>
like image 35
Rick Avatar answered Oct 23 '22 22:10

Rick