diff --git a/web/pgadmin/utils/versioned_template_loader.py b/web/pgadmin/utils/versioned_template_loader.py
index 8e8259fe..cfb513cc 100644
--- a/web/pgadmin/utils/versioned_template_loader.py
+++ b/web/pgadmin/utils/versioned_template_loader.py
@@ -6,53 +6,30 @@
 # This software is released under the PostgreSQL Licence
 #
 ##########################################################################
+import os
 from flask.templating import DispatchingJinjaLoader
 from jinja2 import TemplateNotFound
 
 
 class VersionedTemplateLoader(DispatchingJinjaLoader):
     def get_source(self, environment, template):
-        template_path_parts = template.split("#", 3)
-
-        postgres_versions = (
-            {'name': "10_plus", 'number': 100000},
-            {'name': "9.6_plus", 'number': 90600},
-            {'name': "9.5_plus", 'number': 90500},
-            {'name': "9.4_plus", 'number': 90400},
-            {'name': "9.3_plus", 'number': 90300},
-            {'name': "9.2_plus", 'number': 90200},
-            {'name': "9.1_plus", 'number': 90100},
-            {'name': "9.0_plus", 'number': 90000},
-            {'name': "default", 'number': 0}
-        )
-
-        gpdb_versions = (
-            {'name': "gpdb_5.0_plus", 'number': 80323},
-            {'name': "5_plus", 'number': 80323},
-            {'name': "default", 'number': 0}
-        )
-
-        server_versions = postgres_versions
-        if len(template_path_parts) == 1:
+        specified_version_number, exists = parse_version(template)
+        if not exists:
             return super(VersionedTemplateLoader, self).get_source(
                 environment, template
             )
 
-        if len(template_path_parts) == 4:
-            path_start, server_type, specified_version_number, file_name = \
-                template_path_parts
-            if server_type == 'gpdb':
-                server_versions = gpdb_versions
-        else:
-            path_start, specified_version_number, file_name = \
-                template_path_parts
-
-        for server_version in server_versions:
-            if server_version['number'] > int(specified_version_number):
+        template_dir, file_name = parse_template(template)
+
+        for version_mapping in get_version_mapping(template):
+            if version_mapping['number'] > specified_version_number:
                 continue
 
-            template_path = path_start + '/' + \
-                server_version['name'] + '/' + file_name
+            template_path = '/'.join([
+                template_dir,
+                version_mapping['name'],
+                file_name
+            ])
 
             try:
                 return super(VersionedTemplateLoader, self).get_source(
@@ -61,3 +38,50 @@ class VersionedTemplateLoader(DispatchingJinjaLoader):
             except TemplateNotFound:
                 continue
         raise TemplateNotFound(template)
+
+
+def parse_version(template):
+    template_path_parts = template.split("#", 3)
+    if len(template_path_parts) == 1:
+        return "", False
+
+    if len(template_path_parts) == 3:
+        _, version, _ = template_path_parts
+        return int(version), True
+
+    if len(template_path_parts) == 4:
+        _, _, version, _ = template_path_parts
+        return int(version), True
+
+    raise TemplateNotFound(template)
+
+def parse_template(template):
+    template_path_parts = template.split("#", 3)
+    return template_path_parts[0].strip('\\').strip('/'), \
+        template_path_parts[-1].strip('\\').strip('/')
+
+def get_version_mapping(template):
+    template_path_parts = template.split("#", 3)
+
+    server_type = None
+    if len(template_path_parts) == 4:
+        _, server_type, _, _ = template_path_parts
+
+    if server_type == 'gpdb':
+        return (
+            {'name': "gpdb_5.0_plus", 'number': 80323},
+            {'name': "5_plus", 'number': 80323},
+            {'name': "default", 'number': 0}
+        )
+
+    return (
+            {'name': "10_plus", 'number': 100000},
+            {'name': "9.6_plus", 'number': 90600},
+            {'name': "9.5_plus", 'number': 90500},
+            {'name': "9.4_plus", 'number': 90400},
+            {'name': "9.3_plus", 'number': 90300},
+            {'name': "9.2_plus", 'number': 90200},
+            {'name': "9.1_plus", 'number': 90100},
+            {'name': "9.0_plus", 'number': 90000},
+            {'name': "default", 'number': 0}
+        )
