Pyramid: get the application absolute URL

Is there a way to get the absolute URL of the pyramid application in the main () function? I want to add it to the global settings, so it could be called every time (in templates and js files). There are some functions in the pyramid documents that would help, but they all need a query object and must invoke a view. Thank.

+5
source share
2 answers

A pyramid (like most WSGI applications) can be mounted on any domain and url prefix. Thus, the application itself does not know which URLs are responsible for it unless you specify it directly in your application (for example, the INI parameter).

request.application_url ... application_url , URL , - .

+4

, "" :

mako , JS , ajax/etc

    <script type="text/javascript" charset="utf-8">
        <%
            app_url = request.route_url('home').rstrip('/')
        %>
        APP_URL = '${app_url}';
    </script>
+3

All Articles