Introduction to Flask UPNL 24 T H WORKSHOP

  • Slides: 61
Download presentation
Introduction to Flask UPNL 24 T H WORKSHOP KIM JAE CHAN

Introduction to Flask UPNL 24 T H WORKSHOP KIM JAE CHAN

Flask

Flask

Python

Python

Python werkzeug based

Python werkzeug based

Python werkzeug based microframework

Python werkzeug based microframework

Python werkzeug based microframework

Python werkzeug based microframework

Python?

Python?

Guido van Rossum

Guido van Rossum

Guido van Rossum

Guido van Rossum

Guido van Rossum 2005 -2012 Google

Guido van Rossum 2005 -2012 Google

Guido van Rossum 2005 -2012 Google 2013 - Dropbox

Guido van Rossum 2005 -2012 Google 2013 - Dropbox

Guido van Rossum Script

Guido van Rossum Script

Guido van Rossum Script Easy

Guido van Rossum Script Easy

Guido van Rossum Script Easy Popular

Guido van Rossum Script Easy Popular

def factorial(x): return x <= 0 and 1 or factorial(x-1) * x if __name__

def factorial(x): return x <= 0 and 1 or factorial(x-1) * x if __name__ == '__main__': print factorial(100)

def factorial(x): return x <= 0 and 1 or factorial(x-1) * x if __name__

def factorial(x): return x <= 0 and 1 or factorial(x-1) * x if __name__ == '__main__': print factorial(100) def factorial(x): return reduce(lambda x, y: x * y, range(1, x+1)) if __name__ == '__main__': print factorial(100)

def factorial(x): return x <= 0 and 1 or factorial(x-1) * x if __name__

def factorial(x): return x <= 0 and 1 or factorial(x-1) * x if __name__ == '__main__': print factorial(100) def factorial(x): return reduce(lambda x, y: x * y, range(1, x+1)) if __name__ == '__main__': print factorial(100) def factorial(x): result = 1 for i in range(1, x+1): result *= i return result if __name__ == '__main__': print factorial(100)

Python werkzeug based microframework

Python werkzeug based microframework

Werkzeug

Werkzeug

One of WSGI implementation

One of WSGI implementation

WSGI?

WSGI?

Web Server Gateway Interface

Web Server Gateway Interface

Web Server Python Application Python Framework

Web Server Python Application Python Framework

Request Web Server Python Application Python Framework

Request Web Server Python Application Python Framework

Request Python Application Python Framework Web Server Response

Request Python Application Python Framework Web Server Response

WSGI Request Python Application Python Framework Web Server Response

WSGI Request Python Application Python Framework Web Server Response

Python werkzeug based microframework

Python werkzeug based microframework

Microframework

Microframework

Micro + framework

Micro + framework

Micro

Micro

django pip install django-admin. py startproject <project_name> cd <project_name> coding. . python manage. py

django pip install django-admin. py startproject <project_name> cd <project_name> coding. . python manage. py runserver

django pip install django-admin. py startproject <project_name> cd <project_name> coding. . python manage. py

django pip install django-admin. py startproject <project_name> cd <project_name> coding. . python manage. py runserver ASP. NET Create project in Visual Studio. Many, many files are automatically created. But almost files are useless. coding. . Press F 5 to debug

Flask pip install flask Open vim coding. . ? ? ? PROFIT!

Flask pip install flask Open vim coding. . ? ? ? PROFIT!

micro != lack of feature

micro != lack of feature

micro != lack of feature start quickly

micro != lack of feature start quickly

micro != lack of feature start quickly simple to use

micro != lack of feature start quickly simple to use

micro != lack of feature start quickly simple to use structural flexibility

micro != lack of feature start quickly simple to use structural flexibility

micro != lack of feature start quickly simple to use structural flexibility extendable

micro != lack of feature start quickly simple to use structural flexibility extendable

Examples

Examples

app. py from flask import Flask app = Flask(__name__) @app. route('/') def index(): return

app. py from flask import Flask app = Flask(__name__) @app. route('/') def index(): return u‘Hello, World!' if __name__ == '__main__': app. run(debug=True)

app. py from flask import Flask app = Flask(__name__) @app. route('/') def index(): return

app. py from flask import Flask app = Flask(__name__) @app. route('/') def index(): return u'Hello, World!‘ @app. route('/<name>') def index_name(name): return u'Hello, ' + name if __name__ == '__main__': app. run(debug=True)

app. py from flask import Flask app = Flask(__name__) @app. route('/') def index(): return

app. py from flask import Flask app = Flask(__name__) @app. route('/') def index(): return u'Hello, World!‘ @app. route('/<name>') @app. route('/<name>/<int: times>') def index_name(name, times=None): if not times: times = 1 return (u'Hello, ' + name + '! ') * times if __name__ == '__main__': app. run(debug=True)

I want to create HTML page!

I want to create HTML page!

templates/index. html <!doctype html> <head> <meta charset="utf-8" /> <title>Test. Page</title> </head> <body> <h 1>{{

templates/index. html <!doctype html> <head> <meta charset="utf-8" /> <title>Test. Page</title> </head> <body> <h 1>{{ content }}<h 1> </body> </html>

templates/index. html <!doctype html> <head> <meta charset="utf-8" /> <title>Test. Page</title> </head> <body> <h 1>{{

templates/index. html <!doctype html> <head> <meta charset="utf-8" /> <title>Test. Page</title> </head> <body> <h 1>{{ content }}<h 1> </body> </html> app. py from flask import Flask, render_template app = Flask(__name__) @app. route('/') def index(): return render_template('index. html', content=u'Hello, World!') @app. route('/<name>/<int: times>') def index_name(name, times=None): if not times: times = 1 content = (u'Hello, ' + name + '! ') * times return render_template('index. html', content=content) if __name__ == '__main__': app. run(debug=True)

Conclusion

Conclusion

Web development is easy to start

Web development is easy to start

Web development is easy to start Flask is useful tool

Web development is easy to start Flask is useful tool

Web development is easy to start Flask is useful tool Python is also good

Web development is easy to start Flask is useful tool Python is also good tool

Web development is easy to start Flask is useful tool Python is also good

Web development is easy to start Flask is useful tool Python is also good tool Don’t be afraid of web

Most important thing is

Most important thing is

Most important thing is Your idea.

Most important thing is Your idea.

Reference • http: //python. org • http: //flask. pocoo. org • http: //werkzeug. pocoo.

Reference • http: //python. org • http: //flask. pocoo. org • http: //werkzeug. pocoo. org • http: //wsgi. readthedocs. org