0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

streamlitでベースURLパスを取得する

Last updated at Posted at 2025-08-21

streamlitの画面のURLが https://sample.com/a/b/c/mypage だったときに、ベースURLパスである /a/b/c の部分を取得する方法です

from streamlit import config

server_config = config.get_options_for_section("server")
base_url_path = server_config.get("baseUrlPath")

よってURL全体を取得したい場合は、以下のようにすれば良い

import streamlit as st
from streamlit import config
from pathlib import Path

server_config = config.get_options_for_section("server")
base_url_path = server_config.get("baseUrlPath")
origin = st.context.headers.get("origin")
url=f"{origin}{base_url_path}/{str(Path(__file__).stem)}"
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?