Please enable JavaScript.
Coggle requires JavaScript to display documents.
zibbs (模組 (cms (view (Class ResetPwdView(view.Method)bp.add_url_rule('…
zibbs
模組
cms
forms
loginForm(Form)
from wtforms import ValidationError
models
Class CMSUser(db.Model):
def
init
(self,username, password, email):
self.username= username
self.password = password
self.email = email
property
#讓def 有屬性
def password(self):
return self._password
password.setter
def password(self, raw_password):
self._password = generate_password_hash(raw_password)
def check_password(self, raw_password):
result = check_password_hash(self.password, raw_password)
return result
view
bp = Blueprint('cms',
name
, url_prefix='/cms')
Class LoginView(views.MethodView):
bp.add_url_rule('/login/', view_func=LoginView.as_view('login'))
Class ResetPwdView(view.Method)
bp.add_url_rule('/restpwd/', view_func=ResetPwdView.as_view('restpwd'))
decorators= [login_required]
common
view
forms
models
front
view
forms
models
邏輯
錯誤
static 放跟根目錄下面
cms templatesdex
base
title
{%block title%}
{%endblock%}
head
{% block head%}
{% endblock%}
page title <h1>
{% block page %}{% endblock%}
main content
{% block main_content %}{% endblock%}
<meta name="csrf-token" content="{{ csrf_token()}}">
index
{% from "common/_macros.html" import static %}
_amcros.html
{% macro static(filename) -%} {%- endmacro %}
{{ url_for ('static', filename= filename)}}
bootstrap
http://cdn.bootcss.com/jquery/3.1.1/jquery.min.js
jq 必須在JS 前面
http://cdn.bootcss.com/bootstrap/3.3.7/css/bootstrap.min.css
http://cdn.bootcss.com/bootstrap/3.3.7/js/bootstrap.min.js
profile
{% block main_content %} {% endblock%}
email
app = Flask(name)
mail.init_app(app)
MAIL_SERVER = "smtp.gmail.com"
MAIL_PORT = '587'
MAIL_USE_TLS = True
MAIL_USERNAME=
"2010.vs.lego@gmail.com
"
MAIL_PASSWORD=
MAIL_USE_SSL: True
MAIL_DEFAULT_SENDER =
"2010.vs.lego@gmail.com
"
https://support.google.com/mail/answer/7104828?hl=zh-Hant
https://github.com/twtrubiks/Flask-Mail-example
https://pythonhosted.org/Flask-Mail/#configuring-flask-mail
JS
id 綁定點事件
manage.py
from flask_script import Manager
from flask_migrate import Migrate, MigrateCommand
from zlbbs import create_app
from exts import db
from apps.cms import models as cms_models
app = create_app()
CMSUser = cms_models.CMSUser
manager = Manager(app)
Migrate(app, db)
manager.add_command('db', MigrateCommand)
manager.option('-u','--username',
dest = 'username')
manager.option('-p',
'--password', dest = 'password')
manager.option('-e',
'--email', dest = 'email')
def create_cms_user(username, password, email):
user = CMSUser(username= username, password= password, email = email )
db.session.add(user)
db.session.commit()
print ('ok')
if
name
== '
main
':
manager.run()
exts.py
config
Zlbbs.py
from flask_wtf import CSRFProtect
登入下面 cms_login.html
<input type="hidden" name="csrf_token" value="{{ csrf_token()}}">
二進制
十進制
config