Flask Web Frameworks for Python

Slides:



Advertisements
Similar presentations
건전지로 달리는 쟝고 세미나. 정재성 Django Web Framework CGI.
Advertisements

Presenter: James Huang Date: Sept. 29,  HTTP and WWW  Bottle Web Framework  Request Routing  Sending Static Files  Handling HTML  HTTP Errors.
Part 2.  Arrays  Functions  Passing Variables in a URL  Passing variables with forms  Sessions.
Lecture 6/2/12. Forms and PHP The PHP $_GET and $_POST variables are used to retrieve information from forms, like user input When dealing with HTML forms.
16/19/2015CS120 The Information Era CS120 The Information Era Chapter 5 – Advanced HTML TOPICS: Introduction to Web Page Forms and Introductory Javascript.
“I drink my WSGI clear” A barebones introduction to Python Web Programming. 3/14/2011.
Web frameworks design comparison draft - please help me improve it.
Sys Prog & Scripting - HW Univ1 Systems Programming & Scripting Lecture 15: PHP Introduction.
Cloud computing lectures: Programming with Google App Engine Keke Chen.
A data retrieval workflow using NCBI E-Utils + Python Part II: Jinja2 / Flask John Pinney Tech talk Tue 19 th Nov.
Putting What We Learned Into Context – WSGI and Web Frameworks A290/A590, Fall /16/2014.
from SimpleHTTPServer import SimpleHTTPRequestHandler import SocketServer httpd = SocketServer.TCPServer((‘’, 8000), SimpleHTTPRequestHandler) httpd.serve_forever()
Standalone Java Application vs. Java Web Application
06/10/2015AJAX 1. 2 Introduction All material from AJAX – what is it? Traditional web pages and operation Examples of AJAX use Creating.
ITM © Port, Kazman1 ITM 352 More on Forms Processing.
CSC 2720 Building Web Applications Server-side Scripting with PHP.
First Indico Workshop WEB FRAMEWORKS Adrian Mönnich May 2013 CERN.
PHP. $_GET / $_POST / $_SESSION PHP uses predefined variables to provide access to important information about the server and requests from a browser.
Google App Engine Data Store ae-10-datastore
Variables When programming it is often necessary to store a value for use later on in the program. A variable is a label given to a location in memory.
App Engine Web App Framework Jim Eng
ITM © Port, Kazman1 ITM 352 More on Forms Processing.
Copyright 2007 Byrne Reese. Distributed under Creative Commons, share and share alike with attribution. 1 Intermediate Perl Programming Class Two Instructor:
CSC 2720 Building Web Applications Basic Frameworks for Building Dynamic Web Sites / Web Applications.
LECTURE 14 Web Frameworks. WEB DEVELOPMENT CONTINUED Web frameworks are collections of packages or modules which allow developers to write web applications.
Intro Web Applications Andrew Benson – ScottyLabs – CrashCourse F14.
Ruby on Rails. Web Framework for Ruby Designed to make it easier to develop, deploy, and maintain web applications Design with Model-View-Controller –almost.
Basic Concepts for Python Web Development. What Does Make Python Different Batter Software QA Developer Productivity Advance Program Portability Support.
PHP – Hypertext Preprocessor.
1 Using MVC 6. MVC vs. ASP Web Forms Both run under ASP.NET Can coexist In Web Forms, browser requests page. xxx.aspx and xxx.aspx.cs on the server Page.
CGS 3066: Web Programming and Design Spring 2017
JSP Based on
Forms and PHP.
Introduction to Information Security
Introduction to Dynamic Web Programming
Ember, AngularJS, Backbone.js, Knockout, … eeem??
How to Write Web Forms By Mimi Opkins.
18 – Web applications: Server-side code (PhP)
Net-centric Computing
Lecture 14 Web Frameworks.
Play Framework: Introduction
Upnl 24th workshop kim jae chan
Recitation – Week 8 Pranut jain.
Passing variables between pages
PHP Hypertext Preprocessor
Python Web Development
JavaScript: ExpressJS Overview
PHP FORM HANDLING Post Method
Topics web applications Practical Biocomputing Week 12.
Lecture 19: Forms and uploading files
Servlets and Java Server Pages
>> PHP: Form-Variables & Submission
CMPE 280 Web UI Design and Development January 30 Class Meeting
Software Engineering for Internet Applications
Abel Sanchez, John R. Williams
HTTP GET vs POST SE-2840 Dr. Mark L. Hornick.
CMPE 280 Web UI Design and Development January 29 Class Meeting
Web Programming Language
RPi 2/3 GPIO + Web(Flask)
Web Programming Language
RESTful Web Services.
Lecture 21 More On Django.
PHP Lecture 11 Kanida Sinmai
PHP-II.
Introduction to PHP.
<form> Handling
CS/COE 1520 Jarrett Billingsley
PHP By Prof. B.A.Khivsara Note: The material to prepare this presentation has been taken from internet and are generated only for students reference and.
CMPE 280 Web UI Design and Development August 27 Class Meeting
Web Forms.
Presentation transcript:

Flask Web Frameworks for Python jyheo@hansung.ac.kr

Web Frameworks for Python A Web framework is a collection of packages or modules to write Web applications or services without having to handle such low-level details as protocols, sockets or process/thread management. Popular frameworks (https://wiki.python.org/moin/WebFrameworks/) Django web2py Flask Bottle CherryPy Raspbian includes Flask, don’t need to install it.

Flask - Minimal Application pi@raspberrypi:~ $ cat hello.py from flask import Flask app = Flask(__name__) @app.route('/') def hello_world(): return 'Hello, World!' if __name__ == '__main__': app.run(host='0.0.0.0’) pi@raspberrypi:~ $ python3 hello.py * Running on http://0.0.0.0:5000/ (Press CTRL+C to quit) 192.168.0.129 - - [02/Nov/2017 10:52:38] "GET / HTTP/1.1" 200 - 192.168.0.129 - - [02/Nov/2017 10:52:38] "GET /favicon.ico HTTP/1.1" 404 -

Route() Decorator route() decorator is used to bind a function to a URL from flask import Flask app = Flask(__name__) @app.route('/') def index(): return 'Index Page' @app.route('/hello') def hello(): return 'Hello World' if __name__ == '__main__': app.run(host='0.0.0.0')

Variable to URL from flask import Flask app = Flask(__name__) @app.route('/user/<username>') def show_user_profile(username): # show the user profile for that user return 'User %s' % username @app.route('/post/<int:post_id>') def show_post(post_id): # show the post with the given id, the id is an integer return 'Post %d' % post_id if __name__ == '__main__': app.run(host='0.0.0.0')

Templates from flask import Flask from flask import render_template app = Flask(__name__) @app.route('/greeting') @app.route('/greeting/<name>') def hello(name=None): return render_template('greeting.html', name=name) if __name__ == '__main__': app.run(host='0.0.0.0')

Templates render_template('greeting.html', name=name) greenting.html must be stored in templates/ $ cat templates/greeting.html <!doctype html> <title>Hello from Flask</title> {% if name %} <h1>Hello {{ name }}!</h1> {% else %} <h1>Hello World!</h1> {% endif %}

Form & Request Object from flask import Flask, request @app.route('/formtest', methods=['POST', 'GET']) def form_test(): if request.method == 'POST': return 'Username: %s' % (request.form['username']) else: return ''' <form action="/formtest" method="post"> Name: <input name="username" type="text" /> <br/> <input value="Send" type="submit" /> </form> '''

Session https://gist.github.com/jyheo/b53dd1f868a4ef25a282 http://127.0.0.1:5000/logout

Tutorial http://flask.pocoo.org/docs/0.12/tutorial/

Exercise Write an BBS web service based on these example code. @app.route('/list') def list(): retstr = "" with open('list.txt') as f: for l in f.readlines(): retstr += l + '<br/>' return retstr @app.route('/write', methods=['POST', 'GET']) def write_article(): if request.method == 'POST': article = request.form['article'] with open('list.txt', 'a') as f: f.write(article) return 'Write Successful' return 'Write Error' else: return ''' <form action="/write" method="post"> Article: <input name="article" type="text" /> <br/> <input value="Write" type="submit" /> </form> ''' Write an BBS web service based on these example code. Use templates! Hint: ‘for’ can be used in a template!