LoginSignup
0
2

More than 1 year has passed since last update.

【Python × bottle】 PCで立ち上げたローカルのサーバーに、スマホからアクセスする方法

Last updated at Posted at 2021-11-05

目的

Python のライブラリ bottle を使用してローカルなサーバーを作成する
手持ちのスマホから作成したサーバーにアクセスする
(作成したサーバーへPC以外を使用して接続するのに少し詰まった。備忘録として載せる。)

手順

① : bottle でサーバーを作成
② : PCとスマホ の wifi環境 を統一する
③ : PCから wifi のIPアドレスト取得する
④ : ③のIPアドレスをもとに スマホからサーバーへアクセス

① : bottle でサーバーを作成

※Pythonの環境構築 や bottleのインストール については省略

BottleSample.py
from bottle import route, run, template

@route('/hello/<name>')
def index(name):
    return template('<b>Hello {{name}}</b>!', name=name)

# ポートは任意 (スマホから接続するときに使用する)
run(host="0.0.0.0", port=200)

② : PCとスマホ の wifi環境 を統一する

PCとスマホ で使用する wifi を同じにする

③ : PCから wifi のIPアドレスト取得する

この記事を参考に IPアドレス を調べる

④ : ③のIPアドレスをもとに スマホからサーバーへアクセス

URL : http://③で調べたIPアドレス:①で決めたポート番号/
(例 : http://192.168.~~~.~~~:200/ )
※ ~~~ には適切な数字を入れてください

↓赤丸のところにURLを入力する

http://192.168.~~~.~~~:200/hello/Qiita を入力

結果
image.png

0
2
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
2