python flask 绑定多个独立域名并自动判断域名来路显示页面信息
你确定是判断来路(referer)而不是主机头(host)么?按理说你多个域名最好用主机头区分,因为来路可能是空的。
不管怎么说,简单写几句,你参考下
from flask import Flask, request
app = Flask(__name__)
@app.route('/')
def index():
host = request.host
referer = request.referrer
if host == "domain1.com":
return "You are visiting Domain 1"
elif host == "domain2.com":
return "You are visiting Domain 2"
else:
return "You are visiting an unknown domain"
if __name__ == '__main__':
app.run(debug=True)
不知道你这个问题是否已经解决, 如果还没有解决的话:先试一下作用
>>> from werkzeug.security import generate_password_hash
>>> hash = generate_password_hash('mima')
>>> hash
'pbkdf2:sha256:50000$S9FPhxbX$4f164ff06b409769e44556bcd9d8f906ca82998e433410f85898245e40ecd4d3'
在flask shell里输入如上,密码mima被加密成功
>>> from werkzeug.security import check_password_hash
>>> check_password_hash(hash,'haha')
False
>>> check_password_hash(hash,'mima')
True
验证也成功
from werkzeug.security import generate_password_hash, check_password_hash
class User(db.Model):
__tablename__='login'
id = db.Column(db.Integer,primary_key=True)
name = db.Column(db.String(16),unique=True)
#password = db.Column(db.String(16),unique=True)
password_hash = db.Column(db.String(128))
@property
def password(self):
raise AttributeError('password is not a readable attribute')
@password.setter
def password(self, password):
self.password_hash = generate_password_hash(password)
def verify_password(self, password):
return check_password_hash(self.password_hash, password)
def __repr__(self):
return 'name: %s' % self.name
>>> from app import User
>>> a = User()
>>> a.password = '123456'
>>> a.password
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "C:\Users\howver\PycharmProjects\untitled14\sql.py", line 18, in password
raise AttributeError('password is not a readable attribute')
AttributeError: password is not a readable attribute
现在password已经不存在了
>>> a.password_hash
'pbkdf2:sha256:150000$q7aOkj3o$2d676c99e4cb39091a8f34e2da014837da5702719e6a179ba87ab4795669c192'
>>>
成功