If you're just worried about code organization and want the JS code in a separate file, you could move it to its own template and then include it where needed. For example, move your JS code to a file like /views/my.js. Then in your view:
<script>
{{include 'my.js'}}
</script>
However, that will be somewhat inefficient if you've got lots of Javascript code but only a little bit of dynamically generated web2py content mixed in. An alternative is to define the dynamically generated web2py variables in one block of Javascript in the template, and then load a static JS file that simply refers to those variables (this is how web2py_ajax.html works -- notice that it defines several JS variables, which are then used by web2py.js). So, in your view:
<script>
var someVar = '{{=T('some phrase to be translated')}}';
var someURL = '{{=URL('default', 'myfunction')}}';
</script>
<script src="{{=URL('static', 'js', 'my.js')}}"></script>
Then in my.js, you can refer to someVar and someURL.
Anthony