FlaskとDjangoの対比

2919 ワード

1 ) Flask
Flask    “ ”,    Micro Framework ,  Django    Flask            ,           
Flask   、  ,     ,         ,                ,            Python  
    ,       web     ,        
         
        web     API
         ,           ,                
            Django
Django                , Flask              
Flask     , Python          Flask ,   Django        
Flask                 Django ,    NoSQL            Django
Flask   Django    Pythonic ,  Python   philosophy     

( 2 ) Django
Django    ,   web   ,   ORM      ,         
Django       ,    “      ”   
Django     ORM     ,        SQLAlchemy
Django            ,               Jinja
Django    ORM    Django             ,      MongoDB   NoSQL   ,           ,     Django+SQL          , Django+NoSQL     Django      
Django      Jinja         
Django          app     
Django             :  、  、  
Django   、  、  ,     Flask , Django          
Django   Python web      ,   ,       ,    Python  ,         Django  ,             
Django        ,      、  ,      

flask #!/user/bin/env python # -_ coding:utf-8--#by Havoc from flask import Flask初期化参照Flask from flask import render_template from flask import redirect#リダイレクト使用
app = Flask(name)
@app.route(‘/student’,methods=[‘GET’]) def home_index(): return ‘Hello World’
@app.route(‘/detail’) def article_detail(): return render_template(‘detail.html’)
@app.route(‘/’) def index(): return rediret(‘/detail/’)
@app.route(‘/login//’) def show_welocme(username): return ‘Hello,%s’ % username
if name==’main‘: app.run(host=’127.0.0.1’,port=25532,debug=True)
Flask接続sqlserver
#!/user/bin/env python # -_ coding:utf-8 -- # by Havoc # -- coding:utf-8 --
import pymssql
class MSSQL: def init(self,host,user,pwd,db): self.host = host self.user = user self.pwd = pwd self.db = db
  def __GetConnect(self):
    if not self.db:
        raise(NameError,"         ")
    self.conn = pymssql.connect(host=self.host,user=self.user,password=self.pwd,database=self.db,charset="utf8")
    cur = self.conn.cursor()
    if not cur:
        raise(NameError,"       ")
    else:
        return cur

def ExecQuery(self,sql):
    cur = self.__GetConnect()
    cur.execute(sql)
    resList = cur.fetchall()

    #           
    self.conn.close()
    return resList

def ExecNonQuery(self,sql):
    cur = self.__GetConnect()
    cur.execute(sql)
    self.conn.commit()
    self.conn.close()

# ms = MSSQL(host=”1***”,user=”“,pwd=”“,db=”**”) ms = MSSQL(host=”“,user=”“,pwd=”“,db=”“) reslist = ms.ExecQuery(“select * from System_Users”) for i in reslist: print (i)
# newsql=”update System_Users set name=’%s’ where id=1”%u’Havoc’ # print (newsql) ms.ExecNonQuery(newsql.encode(‘utf-8’))
Diango https://www.cnblogs.com/feixuelove1009/p/5823135.html