[Flask] 学习笔记1:如何清除占用了localhost的process

1. 一个小的demo-来自廖雪峰的教程:https://www.liaoxuefeng.com/wiki/0014316089557264a6b348958f449949df42a6d3a2e542c000/001432012745805707cb9f00a484d968c72dbb7cfc90b91000

#!/usr/bin/env python3
# -*- coding: utf-8 -*-

from flask import Flask
from flask import request

app = Flask(__name__)

@app.route('/', methods=['GET', 'POST'])  #http://127.0.0.1:5000/ go to main page
def home():
    return '<h1>Home</h1>'

@app.route('/signin', methods=['GET']) #http://localhost:5000/signin go to sign in form.
def signin_form():
    return '''<form action="/signin" method="post">
              <p><input name="username"></p>
              <p><input name="password" type="password"></p>
              <p><button type="submit">Sign In</button></p>
              </form>'''

@app.route('/signin', methods=['POST']) 
def signin():
    # 需要从request对象读取表单内容:
    if request.form['username']=='admin' and request.form['password']=='password':
        return '<h3>Hello, admin!</h3>'
    return '<h3>Bad username or password.</h3>'

if __name__ == '__main__':
    app.run()

# Run in a specify sever?
# app.run(
#         host = '0.0.0.0',
#         port = 7777,  
#         debug = True 
#     )

2. 清除占用了localhost的process:

kill the process currently using a port on localhost in windows

(1)Run command-line as an Administrator.

netstat -ano | findstr :yourPortNumber

(2)Then you execute this command after identify the PID.

(3) Done!!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值