diff --git a/notebook/templates/edit.html b/notebook/templates/edit.html
index 4a4cba993..ea49f89ab 100644
--- a/notebook/templates/edit.html
+++ b/notebook/templates/edit.html
@@ -11,7 +11,7 @@
{% block bodyclasses %}edit_app {{super()}}{% endblock %}
{% block params %}
-data-base-url="{{base_url}}"
+data-base-url="{{base_url | urlencode}}"
data-file-path="{{file_path}}"
{{super()}}
{% endblock %}
diff --git a/notebook/templates/terminal.html b/notebook/templates/terminal.html
index 3315a24dc..234d6e939 100644
--- a/notebook/templates/terminal.html
+++ b/notebook/templates/terminal.html
@@ -6,7 +6,7 @@
{% block params %}
-data-base-url="{{base_url}}"
+data-base-url="{{base_url | urlencode}}"
data-ws-path="{{ws_path}}"
{% endblock %}