Question

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.

Was it helpful?

Solution

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.

OTHER TIPS

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>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top