Set the current directory when running a SimpleHTTPServer

后端 未结 2 1400
醉梦人生
醉梦人生 2021-01-30 20:30

Is there any way to set the directory where you want to start a SimpleHTTPServer or BaseHTTPServer?

相关标签:
2条回答
  • 2021-01-30 20:52

    Doing it without changing directory on Linux:

    bash -c "cd /your/path; python -m SimpleHTTPServer"
    
    0 讨论(0)
  • 2021-01-30 21:04

    If you're using SimpleHTTPServer directly from command line, you can simply use shell features:

    pushd /path/you/want/to/serve; python -m SimpleHTTPServer; popd
    

    In Python 3 you have to use:

    pushd /path/you/want/to/serve; python -m http.server; popd
    

    The SimpleHTTPServer module has been merged into http.server in Python 3.0

    0 讨论(0)
提交回复
热议问题