You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

35 lines
1000 B

#!/usr/bin/env python3
"""
快速端口测试 - 检测Django服务器运行在哪个端口
"""
import requests
import sys
def test_ports():
"""测试常用端口"""
ports = [8000, 8001, 8080, 8081]
for port in ports:
try:
url = f"http://127.0.0.1:{port}/api/health/"
response = requests.get(url, timeout=3)
if response.status_code == 200:
print(f"✅ Django服务器运行在端口 {port}")
print(f"🔗 API地址: http://127.0.0.1:{port}/api/")
return port
except:
continue
print("❌ 未找到运行中的Django服务器")
print("💡 请确保Django服务器正在运行")
return None
if __name__ == "__main__":
port = test_ports()
if port:
print(f"\n📋 可以使用以下命令测试:")
print(f"curl http://127.0.0.1:{port}/api/health/")
sys.exit(0)
else:
sys.exit(1)