标签:import methods 需要 url 访问 and 127.0.0.1 .com port
-安装完python,需要手动设置pip环境变量,找到python安装目录的Scripts文件夹中就是根目录,比如C:\Python27\Scripts
。设置完环境变量即可安装第三方模块了,安装时为了提高速度可以使用阿里镜像,方法如下
C:\Users\xxx\AppData\Roaming
,xxx是windows用户名pip.ini
,其内容填入下面内容即可[global]
index-url=http://mirrors.aliyun.com/pypi/simple/
[install]
trusted-host=mirrors.aliyun.com
pip install Flask
from flask import Flask
from flask import request
print __name__
app = Flask(__name__)
@app.route(‘/‘, methods=[‘GET‘, ‘POST‘])
def home():
return ‘<h1>Home</h1>‘
@app.route(‘/signin‘, methods=[‘GET‘])
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():
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()
python app.py
http://127.0.0.1:5000/
标签:import methods 需要 url 访问 and 127.0.0.1 .com port
原文地址:https://www.cnblogs.com/winfred/p/10371956.html