diff --git a/datasette/views/base.py b/datasette/views/base.py
index 92ec03ca..06968e03 100644
--- a/datasette/views/base.py
+++ b/datasette/views/base.py
@@ -218,7 +218,7 @@ class DataView(BaseView):
elif kwargs.get("table"):
kwargs["table"] = urllib.parse.unquote_plus(kwargs["table"])
- should_redirect = "/{}-{}".format(name, expected)
+ should_redirect = self.ds.urls.path("{}-{}".format(name, expected))
if kwargs.get("table"):
should_redirect += "/" + urllib.parse.quote_plus(kwargs["table"])
if kwargs.get("pk_path"):
diff --git a/datasette/views/special.py b/datasette/views/special.py
index 25abb193..28af1e99 100644
--- a/datasette/views/special.py
+++ b/datasette/views/special.py
@@ -64,7 +64,7 @@ class AuthTokenView(BaseView):
raise Forbidden("Root token has already been used")
if secrets.compare_digest(token, self.ds._root_token):
self.ds._root_token = None
- response = Response.redirect("/")
+ response = Response.redirect(self.ds.urls.instance())
response.set_cookie(
"ds_actor", self.ds.sign({"a": {"id": "root"}}, "actor")
)
@@ -81,7 +81,7 @@ class LogoutView(BaseView):
async def get(self, request):
if not request.actor:
- return Response.redirect("/")
+ return Response.redirect(self.ds.urls.instance())
return await self.render(
["logout.html"],
request,
@@ -89,7 +89,7 @@ class LogoutView(BaseView):
)
async def post(self, request):
- response = Response.redirect("/")
+ response = Response.redirect(self.ds.urls.instance())
response.set_cookie("ds_actor", "", expires=0, max_age=0)
self.ds.add_message(request, "You are now logged out", self.ds.WARNING)
return response
@@ -172,4 +172,4 @@ class MessagesDebugView(BaseView):
datasette.add_message(request, message, datasette.ERROR)
else:
datasette.add_message(request, message, getattr(datasette, message_type))
- return Response.redirect("/")
+ return Response.redirect(self.ds.urls.instance())
diff --git a/docs/config.rst b/docs/config.rst
index 6dafd69d..ff39f02a 100644
--- a/docs/config.rst
+++ b/docs/config.rst
@@ -272,7 +272,7 @@ Some examples:
base_url
~~~~~~~~
-If you are running Datasette behind a proxy, it may be useful to change the root URL used for the Datasette instance.
+If you are running Datasette behind a proxy, it may be useful to change the root path used for the Datasette instance.
For example, if you are sending traffic from ``https://www.example.com/tools/datasette/`` through to a proxied Datasette instance you may wish Datasette to use ``/tools/datasette/`` as its root URL.
diff --git a/tests/test_html.py b/tests/test_html.py
index fb86d9d9..6e18e516 100644
--- a/tests/test_html.py
+++ b/tests/test_html.py
@@ -1360,8 +1360,6 @@ def test_metadata_sort_desc(app_client):
assert list(reversed(expected)) == rows
-@pytest.mark.xfail
-@pytest.mark.parametrize("base_url", ["/prefix/", "https://example.com/"])
@pytest.mark.parametrize(
"path",
[
@@ -1373,7 +1371,8 @@ def test_metadata_sort_desc(app_client):
"/fixtures/facetable",
],
)
-def test_base_url_config(base_url, path):
+def test_base_url_config(path):
+ base_url = "/prefix/"
with make_app_client(config={"base_url": base_url}) as client:
response = client.get(base_url + path.lstrip("/"))
soup = Soup(response.body, "html.parser")