Presentation is loading. Please wait.

Presentation is loading. Please wait.

from SimpleHTTPServer import SimpleHTTPRequestHandler import SocketServer httpd = SocketServer.TCPServer((‘’, 8000), SimpleHTTPRequestHandler) httpd.serve_forever()

Similar presentations


Presentation on theme: "from SimpleHTTPServer import SimpleHTTPRequestHandler import SocketServer httpd = SocketServer.TCPServer((‘’, 8000), SimpleHTTPRequestHandler) httpd.serve_forever()"— Presentation transcript:

1

2 from SimpleHTTPServer import SimpleHTTPRequestHandler import SocketServer httpd = SocketServer.TCPServer((‘’, 8000), SimpleHTTPRequestHandler) httpd.serve_forever()

3

4  CGI: Common Gateway Interface ◦ need to start a new process for every request  not recommened ◦ cgi, cgitb module  FastCGI, SCGI(a simpler FastCGI) ◦ uses preforked backgroundprocesses to handle requests  by imbedding interpreters into the web server CGI

5  A standard interface between web server and web applications written in Python  WSGI application will work on any gateway interfaces: CGI, FastCGI, SCGI, mod_python, or mod_wsgi  mod_wsgi: a WSGI server in Apache web server (WCGI-compliant) ◦ embedded mode (integrated with Apache process) ◦ daemon mode which is FastCGI-like  wsgiref module ◦ A reference implementation of WSGI specification ◦ contains a small web server that can be used for testing

6 #!/usr/bin/env python from wsgiref.simple_server import make_server def application(environ, start_response): response_body = 'Hello, world!' status = '200 OK' response_headers = [('Content-Type', 'text/plain')] start_response(status, response_headers) return [response_body] # for testing only server = make_server('localhost', 8051, application) server.serve_forever()  Publishing ◦ upload this program to web server directory (after removing main statements) ◦ http://np.hufs.ac.kr/path/to/hel lo.py  Testing ◦ Run this program by lauching test server ◦ Enter URL on the browser  http://localhost:8051/  or http://localhost:8051/hello.py hello.py:

7  http://webpython.codepoint.net/wsgi_tutorial http://webpython.codepoint.net/wsgi_tutorial

8  MVC ◦ model: data to be displayed and modified ◦ view: display the data of the model to the user  typically implemented by templates ◦ controller  reacts to user actions  tells the model to modify the data, and tells the view code what to display  Frameworks for web app development in Python ◦ Django: https://www.djangoproject.comhttps://www.djangoproject.com  Google App Engine: a PaaS ◦ https://cloud.google.com/appengine/docs https://cloud.google.com/appengine/docs


Download ppt "from SimpleHTTPServer import SimpleHTTPRequestHandler import SocketServer httpd = SocketServer.TCPServer((‘’, 8000), SimpleHTTPRequestHandler) httpd.serve_forever()"

Similar presentations


Ads by Google