```
<%
    version_path = (version + '/') if len(version) > 0 or ''
%>
```

and then use version_path everywhere.

?