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

Slides:



Advertisements
Similar presentations
Django The Web Framework for Perfectionists with Deadlines By: Udi h Bauman, BeeTV.
Advertisements

PHP Form and File Handling
1 Copyright © 2002 Pearson Education, Inc.. 2 Chapter 2 Getting Started.
Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 15 Introduction to Rails.
4 Copyright © 2005, Oracle. All rights reserved. Creating the Web Tier: Servlets.
CakePHP. A framework for developing applications in PHP Inspired by Ruby on Rails Follows MVC design pattern Convention over configuration –No wheel reinventing.
Cobol Files to SQL Databases
CS125 Honors Project Illini TIX Austin Kramer Peter Kowalczyk Rohan Kapoor Jay Bensal.
Social Web Design 1 Darby Chang Social Web Design.
Molecular Biomedical Informatics Web Programming 1.
Copyright © 2004 ProsoftTraining, All Rights Reserved. Lesson 11: Advanced Web Technologies.
AparnaESI Language 1 ESI (Edge Side Includes) Language And Systems By Aparna Yeddula.
DB Relay An Introduction. INSPIRATION Database access is WAY TOO HARD The crux.
By: Lloyd Albin 9/28/2012. We are not talking about a Raspberry Pie.
PHP 5 + MySQL 5 A Perfect 10. Adam Trachtenberg PHP 5 + MySQL 5 = A Perfect mysqli extension i is for improved! All new MySQL extension for PHP.
1/16 Steven Leung Introduction to HTML/CGI/JavaScript Intro to HTML/CGI/JavaScript How the Web Works HTML: Basic Concept CGI: Basic Concept JavaScript:
Building a Web Crawler in Python Frank McCown Harding University Spring 2013 This work is licensed under a Creative Commons Attribution-NonCommercial-
{ Django Deployment Tips, Tricks and Best Practices Erik LaBianca, WiserTogether, Inc.
Rapid Web Development with Python/Django Julian Hill.
Presenter: James Huang Date: Sept. 29,  HTTP and WWW  Bottle Web Framework  Request Routing  Sending Static Files  Handling HTML  HTTP Errors.
Python Hyunjong Lee. contents  Introduction  Syntax & data types  Tools  Python as CGI.
Python Mini-Course University of Oklahoma Department of Psychology Lesson 28 Classes and Methods 6/17/09 Python Mini-Course: Lesson 28 1.
Adding Dynamic Content to your Web Site
Murali Mani SQL-PL Interface. Murali Mani Some Possible Options Web Interface Perl /CGI with Oracle/mySQL Install your own web server and use servlets.
HTTP Request/Response Process 1.Enter URL ( in your browser’s address bar. 2.Your browser uses DNS to look up IP address of server.com.
W EB A PPLICATION D EVELOPMENT A PPLICATION T O B IO -I NFORMATICS -III Vicky Khanna M-Tech Bioinformatics.
PHP and MySQL Database. Connecting to MySQL Note: you need to make sure that you have MySQL software properly installed on your computer before you attempt.
December, 2008 CS-591 Securing Servers: International Capture the Flag 1 Nadine Sundquist CS591-F2008 University of Colorado, Colorado Springs Dr. C. Edward.
1.  Understanding about How to Working with Server Side Scripting using PHP Framework (CodeIgniter) 2.
Creating WordPress Websites. Creating a site on your computer Local server Local WordPress installation Setting Up Dreamweaver.
WHAT IS PHP PHP is an HTML-embedded scripting language primarily used for dynamic Web applications.
Web Development Methodologies Yuan Wang(yw2326). Basic Concepts Browser/Server (B/S) Structure Keywords: Browser, Server Examples: Websites Client/Server.
Web Frameworks: Django Department of Biomedical Informatics University of Pittsburgh School of Medicine
A pro-Django presentation: Brandon W. King SoCal Piggies - May 2007.
Django Web Framework 김형용, 이정민 Framework 2.1. Django High-level Python Web Framework Develop fast Automate the repetitive stuff Follow best practices.
PHP Programming. Topics Background and History of PHP Installation Comments in PHP Variables Conditions Loops Functions File Handling Database Handling.
M. Taimoor Khan * Java Server Pages (JSP) is a server-side programming technology that enables the creation of dynamic,
건전지로 달리는 쟝고 세미나. 파트2 Last time MVC Views and URLconfs.
Cloud computing lectures: Programming with Google App Engine Keke Chen.
FUNCTIONS AND STORED PROCEDURES & FUNCTIONS AND PROTECTING A DB AND PHP (Chapters 9, 15, 18)
Standalone Java Application vs. Java Web Application
CSE 3330 Database Concepts Stored Procedures. How to create a user CREATE USER.. GRANT PRIVILEGE.
Who uses it? MichaelMoore.com What's it all about? Rapid Development Clean, Pragmatic Design.
Templates, Databases and Frameworks. Databases: DBI Common database interface for perl Provides a functional,
MVC Concepts Basics Model-View-Controller (MVC) Concepts for Web Developers SoftUni Team Technical Trainers Software University
Django 101 By: Jason Sumner. Django Overview Django was started in 2003, released under BSD in 2005, and the Django Software Foundation was established.
PHP on a Fast Track a quick introduction to PHP programming by Jarek Francik last time updated in 2012.
הרצאה 4. עיבוד של דף אינטרנט דינמי מתוך Murach’s PHP and MySQL by Joel Murach and Ray Harris.  דף אינטרנט דינמי משתנה עפ " י הרצת קוד על השרת, יכול להשתנות.
Creating a simple database This shows you how to set up a database using PHPMyAdmin (installed with WAMP)
Copyright 2007 Byrne Reese. Distributed under Creative Commons, share and share alike with attribution. Intermediate Perl Programming Class Three Instructor:
HTML A brief introduction HTML1. HTML, what is? HTML is a markup language for describing web documents (web pages). HTML stands for Hyper Text Markup.
(Some from Chapter 11.9 – “Web” 4 th edition and
8 th Semester, Batch 2009 Department Of Computer Science SSUET.
Mysql YUN YEO JOONG. 1 Connecting to and Disconnecting from the Server 1 Connecting to and Disconnecting from the Server shell> mysql – h host -u user.
Intro Web Applications Andrew Benson – ScottyLabs – CrashCourse F14.
Programming for the Web MySQL Command Line Using PHP with MySQL Dónal Mulligan BSc MA
CGS 3066: Web Programming and Design Spring 2016 Introduction to Server-Side Programming.
The Django Web Application Framework zhixiong.hong
BIT 286: Web Applications ASP.Net MVC. Objectives Applied MVC overview Controllers Intro to Routing Views ‘Convention over configuration’ Layout files.
CGS 3066: Web Programming and Design Spring 2017
Introduction to Dynamic Web Programming
MVC Architecture, Symfony Framework for PHP Web Apps
Introduction to CodeIgniter (CI)
MapServer In its most basic form, MapServer is a CGI program that sits inactive on your Web server. When a request is sent to MapServer, it uses.
MVC Framework, in general.
Flask Web Frameworks for Python
Robotics Website By Andy Kelley.
Lecture 21 More On Django.
TN19-TCI: Integration and API management using TIBCO Cloud™ Integration
Presentation transcript:

건전지로 달리는 쟝고 세미나

정재성

Django

Web Framework

CGI

#!/usr/bin/env python import MySQLdb print "Content-Type: text/html\n" print " Books " print " " print " Books " print " " connection = MySQLdb.connect(user='me', passwd='letmein', db='my_db') cursor = connection.cursor() cursor.execute("SELECT name FROM books ORDER BY pub_date DESC LIMIT 10") for row in cursor.fetchall(): print " %s " % row[0] print " " print " " connection.close()

Don’t reinvent the wheel.

MVC

#!/usr/bin/env python import MySQLdb print "Content-Type: text/html\n" print " Books " print " " print " Books " print " " connection = MySQLdb.connect(user='me', passwd='letmein', db='my_db') cursor = connection.cursor() cursor.execute("SELECT name FROM books ORDER BY pub_date DESC LIMIT 10") for row in cursor.fetchall(): print " %s " % row[0] print " " print " " connection.close()

models.py views.py urls.py template.html

# models.py (the database tables) from django.db import models class Book(models.Model): name = models.CharField(max_length=50) pub_date = models.DateField()

# views.py (the business logic) from django.shortcuts import render_to_response from models import Book def latest_books(request): book_list = Book.objects.order_by('- pub_date')[:10] return render_to_response('latest_books.html', {'book_list': book_list})

# urls.py (the URL configuration) from django.conf.urls.defaults import * import views urlpatterns = patterns('', (r'^latest/$', views.latest_books), )

# latest_books.html (the template) Books Books {% for book in book_list %} {{ book.name }} {% endfor %}

Loosely coupled

History

Install

Install Python

Install Django

$ tar xzvf Django-*.tar.gz $ cd Django-* $ python setup.py install

Databases 코끼리, 나뭇잎 돌고래, 11g

Databases PostgreSQL, SQLite MySQL, Oracle

Starting a Project

$ django-admin.py startproject courserating

courserating/ __init__.py manage.py settings.py urls.py

Running DEV Server

$ python manage.py runserver

$ python manage.py runserver Validating models... 0 errors found Django version 1.2.1, using settings 'courserating.settings' Development server is running at Quit the server with CONTROL-C.

Views and URLconfs

First Django-Powered Page

# views.py from django.http import HttpResponse def hello(request): return HttpResponse("Hello world")

# urls.py from django.conf.urls.defaults import * from views import hello urlpatterns = patterns('', ('^hello/$', hello), )

# settings.py... ROOT_URLCONF = 'courserating.urls'...

1. Request /hello/ 2. Look at ROOT_URLCONF 3. Look at URLpatterns 4. Match then call the associated view function 5. The view function returns as HttpResponse 6. Convert HttpResponse to the proper HTTP response

Dynamic Content

>>> import datetime >>> now = datetime.datetime.now() >>> now datetime.datetime(2010, 6, 5, 1, 15, 20, ) >>> print now :15:

# views.py from django.http import HttpResponse import datetime def current(request): now = datetime.datetime.now() html = " Now %s. " % now return HttpResponse(html)

# urls.py from django.conf.urls.defaults import * from views import hello, current urlpatterns = patterns('', ('^hello/$', hello), ('^current/$', current), )

# urls.py from django.conf.urls.defaults import * from views import hello, current urlpatterns = patterns('', ('^hello/$', hello), (‘^current/$', current), (‘^another_current/$', current), )

Dynamic URLs

# urls.py urlpatterns = patterns('', ('^time/$', current), ('^time/plus/1/$', one_hour_ahead), ('^time/plus/2/$', two_hours_ahead), ('^time/plus/3/$', three_hours_ahead), ('^time/plus/4/$', four_hours_ahead), )

urlpatterns = patterns('', #... (r'^time/plus/\d+/$', hours_ahead), #... )

urlpatterns = patterns('', #... (r'^time/plus/(\d{1,2})/$', hours_ahead), #... )

# views.py def hours_ahead(request, offset): try: offset = int(offset) except ValueError: raise Http404() dt = datetime.datetime.now() + datetime.timedelta(hours=offset) html = " In %s hour(s), it will be %s. " % (offset, dt) return HttpResponse(html) # views.py def hours_ahead(request, offset): try: offset = int(offset) except ValueError: raise Http404() dt = datetime.datetime.now() + datetime.timedelta(hours=offset) html = " In %s hour(s), it will be %s. " % (offset, dt) return HttpResponse(html)

Templates

# views.py from django.http import HttpResponse import datetime def current(request): now = datetime.datetime.now() html = " Now %s. " % now return HttpResponse(html)

>>> from django.conf import settings >>> settings.configure() >>> from django.template import Template, Context >>> t = Template('My ID is {{ name }}.') >>> c = Context({'name': ‘hodduc'}) >>> print t.render(c) My ID is hodduc. >>> c = Context({'name': ' r4t5y6 '}) >>> print t.render(c) My ID is r4t5y6. >>> print t

>>> from django.template import Context >>> c = Context({"foo": "bar"}) >>> c['foo'] 'bar' >>> del c['foo'] >>> c['foo'] Traceback (most recent call last):... KeyError: 'foo' >>> c['newvariable'] = 'hello' >>> c['newvariable'] 'hello'

>>> from django.template import Template, Context >>> person = {'name': ‘Yoona', 'age': ‘21'} >>> t = Template('{{ person.name.upper }} is {{ person.age }} years old.') >>> c = Context({'person': person}) >>> t.render(c) u‘YOONA is 21 years old.'

More Templates

{% if girlgeneration %} I Love You! {% else %} Then give it to dogs {% if wondergirls %} Jimotmi {% endif %} {% endif %}

{% for girl in girlgeneration %} {{ girl.name }} {% for a in girl.recent_solo_albums reversed %} {{ a.name }} {% endfor %} {% endfor %}

{% if girlgeneration == wondergirls %} Really?! {% else %} That’s right! {% endif %}

{% if variable > 1 %} {% if variable <= 1.23 %} {% if variable != 'foo' %} {% if variable == "foo" %} {% if variable == True %} {% if variable == [1, 2, 3] %} {% if variable == {'key': 'value'} %}

{{ name|lower }} {{ my_list|first|upper }} {{ my_list|length }} {{ bio|truncatewords:"30" }} {{ pub_date|date:"F j, Y" }} {{ codes|addslashes }} {{ html|striptags }} {{ value|default:"nothing" }}

{# World of Warcraft #} Hello

Templates in Views

# views.py from django.http import HttpResponse import datetime def current(request): now = datetime.datetime.now() html = " Now %s. " % now return HttpResponse(html)

# views.py from django.template import Template, Context from django.http import HttpResponse import datetime def current(request): now = datetime.datetime.now() t = Template(" It is now {{ current_date }}. ") html = t.render(Context({'current_date': now})) return HttpResponse(html)

# /templates/current.html It is now {{ current_date }}.

# views.py from django.template import Template, Context from django.http import HttpResponse import datetime def current(request): now = datetime.datetime.now() fp = open('/templates/current.html') t = Template(fp.read()) fp.close() html = t.render(Context({'current_date': now})) return HttpResponse(html)

# settings.py TEMPLATE_DIRS = ( '/templates', )

# views.py from django.template.loader import get_template from django.template import Context from django.http import HttpResponse import datetime def current(request): now = datetime.datetime.now() t = get_template('current.html') html = t.render(Context({'current_date': now})) return HttpResponse(html)

# views.py from django.shortcuts import render_to_response import datetime def current(request): now = datetime.datetime.now() return render_to_response('current.html', {'current_date': now})

Reusing Templates

# girlgeneration.html {% include 'members/tanggu.html' %}... # tanggu.html Romang

# base.html {% block title %}{% end block %} KAIST {% block content %}{% endblock %} {% block footer %} Daejeon {% endblock %}

# dorm.html {% extends "base.html" %} {% block title %}Penalties{% endblock %} {% block content %}GG{% endblock %} # maru.html {% extends "base.html" %} {% block title %}Hell{% endblock %} {% block content %} Then give it to dogs!{% endblock %}

내일은…

Models

Admin Sites

Forms

Users