Co to jest Python 3 odpowiednik " python - m SimpleHTTPServer"
Jaki jest odpowiednik Pythona 3 python -m SimpleHTTPServer
?
6 answers
From The docs :
Moduł
SimpleHTTPServer
został scalony whttp.server
w Pythonie 3.0. Narzędzie 2to3 automatycznie dostosuje import podczas konwersji źródeł do wersji 3.0.
Więc twoje polecenie to python3 -m http.server
.
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2016-10-03 08:44:59
Odpowiednikiem jest:
python3 -m http.server
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2011-10-30 07:27:48
Używanie narzędzia 2to3.
$ cat try.py
import SimpleHTTPServer
$ 2to3 try.py
RefactoringTool: Skipping implicit fixer: buffer
RefactoringTool: Skipping implicit fixer: idioms
RefactoringTool: Skipping implicit fixer: set_literal
RefactoringTool: Skipping implicit fixer: ws_comma
RefactoringTool: Refactored try.py
--- try.py (original)
+++ try.py (refactored)
@@ -1 +1 @@
-import SimpleHTTPServer
+import http.server
RefactoringTool: Files that need to be modified:
RefactoringTool: try.py
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2013-06-27 19:16:32
Oprócz odpowiedzi Petra, jeśli chcesz powiązać konkretny interfejs zamiast wszystkich interfejsów, możesz użyć flagi-B / --bind.
python -m http.server 8000 --bind 127.0.0.1
Powyższy fragment powinien załatwić sprawę. 8000 to numer portu. 80 jest używany jako standardowy port do komunikacji HTTP.
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2017-09-11 18:44:34
W jednym z moich projektów wykonuję testy z Pythonem 2 i 3. W tym celu napisałem mały skrypt, który uruchamia lokalny serwer niezależnie:
$ python -m $(python -c 'import sys; print("http.server" if sys.version_info[:2] > (2,7) else "SimpleHTTPServer")')
Serving HTTP on 0.0.0.0 port 8000 ...
Jako pseudonim:
$ alias serve="python -m $(python -c 'import sys; print("http.server" if sys.version_info[:2] > (2,7) else "SimpleHTTPServer")')"
$ serve
Serving HTTP on 0.0.0.0 port 8000 ...
Proszę zauważyć, że kontroluję moją wersję Pythona za pomocą środowisk conda, dzięki czemu mogę używać python
zamiast python3
do używania Pythona 3.
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2017-10-05 22:32:20
Polecenie python -m SimpleHTTPServer
jest dla Linuksa. Użyj polecenia python -m http.server 7777
Dla Windows
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2017-04-14 21:24:40