سؤال

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.

هل كانت مفيدة؟

المحلول

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.

نصائح أخرى

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>
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top