python codes as following:
from flask import Flask
from flask import request
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()
It can be successfully executed in python mutual environment, but failed to be executed in win7 cmd as a file app.py. example1: copy codes and paste into python interactive environment as following:
* Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
example2: copy codes and make them saved as a file named "hsiehapp.py"
C:\Users\Administrator\Desktop\python file>python hsiehapp.py
Traceback (most recent call last):
File "hsiehapp.py", line 1, in <module>
from flask import Flask
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python36-32\lib\sit
e-packages\flask\__init__.py", line 19, in <module>
from jinja2 import Markup, escape
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python36-32\lib\sit
e-packages\jinja2\__init__.py", line 33, in <module>
from jinja2.environment import Environment, Template
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python36-32\lib\sit
e-packages\jinja2\environment.py", line 16, in <module>
from jinja2.defaults import BLOCK_START_STRING, \
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python36-32\lib\sit
e-packages\jinja2\defaults.py", line 32, in <module>
from jinja2.tests import TESTS as DEFAULT_TESTS
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python36-32\lib\sit
e-packages\jinja2\tests.py", line 15, in <module>
import decimal
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python36-32\lib\dec
imal.py", line 3, in <module>
from _decimal import *
AttributeError: module 'numbers' has no attribute 'Number'
My python version is python 3.6.1. My operation system is windows7. I am so confused about this, and please help me. thank you...
Aucun commentaire:
Enregistrer un commentaire