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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With