{{=URL(...)}} is web2py template code and therefore only works in templates 
(which must be executed by web2py). Static JS and CSS files are not 
templates and therefore cannot contain Python code.

Instead of serving the JS as a static file, you could generate it 
dynamically and use the @cache.action decorator to make sure it is cached 
by the browser (as well as the server) so you don't re-generate it on every 
request. However, a better option might be to define the URL as a 
Javascript variable, and generate the Javascript variable dynamically 
within your app (e.g., in the layout). For example, in layout.html or in 
the view for a particular page that needs the Javascript file:

<script>
var my_url = '{{=URL(...)}}';
</script>
<script src="{{=URL('static', 'js/myfile.js')}}"></script>

Then the code in myfile.js can refer to the my_url variable, which has been 
defined prior to loading the file.

Anthony

On Tuesday, August 11, 2015 at 4:03:36 AM UTC-4, Alessio Varalta wrote:
>
> Hi, I have a problem with the comand URL. If i use this comand inside a 
> view like 
>
> <html>
>
> </html>
>
> <script>
> <USE of URL>
> <script>
>
> The command work correctly but if a use this comand in a external js like 
> myfile the command doesn't work because the parser don't translate the 
> command
>
> <html>
>
> <html>
> <script src="{{=URL('static','js/myfile.js')}}"></script>
>
> There is a solution?
>

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to