Reminders. Full Django products are due next Thursday! CS370, Günay (Emory) Spring / 6

Similar documents
Django: Views, Templates, and Sessions

Reminders. Github & HTTP steps, together with the minimally viable Django product are due this coming Tuesday! CS370, Günay (Emory) Spring / 8

Technology modeling. Ralf Lämmel Software Languages Team University of Koblenz-Landau

MIT AITI Python Software Development Lab DJ1:

Webdev: Building Django Apps. Ryan Fox Andrew Glassman MKE Python

Tomasz Szumlak WFiIS AGH 23/10/2017, Kraków

CE419 Web Programming. Session 15: Django Web Framework

Django urls Django Girls Tutorial

정재성

generates scaffolding/framework for models, views

Django Data Model Revisited and Testing Introduction

Ninja Typers Web Application Design Document By Marvin Farrell C

Accelerating Information Technology Innovation

Tangent MicroServices Documentation

webkitpony Documentation

Documentation and Deployment

django-scaffold Documentation

Moving to a Sustainable Web Development Environment for Library Web Applications

django-avatar Documentation

Rapid Development with Django and App Engine. Guido van Rossum May 28, 2008

django-avatar Documentation

Django Web Framework: A Comprehensive Introduction and Step by Step Installation

Quoting Wikipedia, software

Graphene Documentation

The Django Web Framework Part II. Hamid Zarrabi-Zadeh Web Programming Fall 2013

django-openid Documentation

About the Tutorial. Audience. Prerequisites. Disclaimer & Copyright. Django

SAURASHTRA UNIVERSITY

L6 Application Programming. Thibault Sellam Fall 2018

wagtail-robots Documentation

Django starting guide

widgets, events, layout loosely similar to Swing test browser, or plugin for testing with real browser on local system

Reminders. Emory Horror Code:

Lecture 10(-ish) Web [Application] Frameworks

Security and Authentication

Project OpenDSA Log Support Final Report

EXPERIENCES MOVING FROM DJANGO TO FLASK

Django MFA Documentation

The syndication feed framework

Front End Programming

AJAX: From the Client-side with JavaScript, Back to the Server

web.py Tutorial Tom Kelliher, CS 317 This tutorial is the tutorial from the web.py web site, with a few revisions for our local environment.

Django Test Utils Documentation

Building a Django Twilio Programmable Chat Application

django-gollum Documentation

Django IPRestrict Documentation

Working with the Seagull Framework. By Demian Turner, Seagull Systems

Accelerating Information Technology Innovation

django-embed-video Documentation

Python. Django. (Web Application Framework - WAF) PyCharm. (Integration Development Environment - IDE)

JAVA For Beginner's Crash Course: Java For Beginners Guide To Program Java, JQuery, & Java Programming (Java For Beginners, Learn Java, JQuery,...

Accelerating Information Technology Innovation

Bambu API Documentation

CS50 Quiz Review. November 13, 2017

djangotribune Documentation

django-embed-video Documentation

django-contact-form Documentation

Django_template3d Documentation

canary Documentation Release 0.1 Branton K. Davis

Django Deployment & Tips daybreaker

Databases/JQuery AUGUST 1, 2018

Linguistic Architecture

Zend Framework for IBM i

Accelerating Information Technology Innovation

Python Web Development With Django By Paul Bissex, Jeff Forcier

Contents. 1. What is otree? 2. The Shell and Python. 3. Example: simple questionnaire. 4. Example: public goods game. 5. Test bots.

Django with Python Course Catalog

django-mongonaut Documentation

The Relational Model

nacelle Documentation

CS637 Midterm Review

django-oauth2-provider Documentation

SAURASHTRA UNIVERSITY

Technology modeling. Ralf Lämmel Software Languages Team University of Koblenz-Landau

Software Test Plan Version 1.0

Easy-select2 Documentation

Web Security. Attacks on Servers 11/6/2017 1

Full Stack Web Developer

South Africa Templates.

CS 2316 Homework 9a GT Room Reservation Login

Django-Select2 Documentation. Nirupam Biswas

django-model-report Documentation

Django-Style Flask. Cody Lee SCALE12x Feb 22, git clone

Google Groups. Using, joining, creating, and sharing. content with groups. What's Google Groups? About Google Groups and Google Contacts

About the Tutorial. Audience. Prerequisites. Disclaimer & Copyright. TurboGears

Django Phantom Theme Documentation

Django REST Framework JSON API Documentation

Module 3 Web Component

Hue Application for Big Data Ingestion

About the Tutorial. Audience. Prerequisites. Copyright & Disclaimer. Joomla

Strategies for Rapid Web Prototyping. Ruby on Rails. Clemens H. Cap

Statirator Documentation

Json Parse Error - No Json Object Could Be Decoded Django Rest Framework

DATABASE SYSTEMS. Database programming in a web environment. Database System Course, 2016

Accelerating Information Technology Innovation

CSc 337 Final Examination December 13, 2013

COMMUNITY PARENTING PLATFORM

7401ICT eservice Technology. (Some of) the actual examination questions will be more precise than these.

OU Mashup V2. Display Page

JAMES BENNETT DJANGOCON EUROPE 3RD JUNE 2015 THE NET IS DARK AND FULL OF TERRORS

Transcription:

Reminders Full Django products are due next Thursday! CS370, Günay (Emory) Spring 2015 1 / 6

Reminders Full Django products are due next Thursday! Let's start by quizzing you. CS370, Günay (Emory) Spring 2015 1 / 6

Exit quiz: Persistent Data and Databases in Web Development To maintain user sessions, what pieces of persistent information must be stored on the client and the server side? What is SQL injection attack and how do you protect against it in your webapp? Entry survey: Django Model-View-Controller (or Template) Architecture What's the point of Django's urls.py le? Where's the database in a Django app and how do yo manipulate it?

Web Programming in Django Introduction to its Model-View-Controller (or Template) Architecture CS370 SE Practice & Startup, Cengiz Günay (Some slides courtesy of Eugene Agichstein and the Internets) Snowpacolypse ATL 2014 CS370, Günay (Emory) Django MVC intro Spring 2015 3 / 6

high-level Python Web framework that encourages rapid development and clean, pragmatic design. Django was designed to handle two challenges: intensive deadlines stringent requirements of the experienced Web developers who wrote it. It lets you build high-performing, elegant Web applications quickly. Focuses on automating as much as possible 1/24/2013 CS 370, Spring 2012 18

Approach: Model-View-Controller Model: maintain state of application. Typically done with a database View: output to client, usually as HTML code, rendered by a web browser. Controller: interaction with user. handles user input, processes data and communicates with Model to save state. Formalized in 1979 1/29/2013 CS 370, Spring 2012 2

MVC 1/29/2013 CS 370, Spring 2012 3

1 Visitor's browser asks for a URL. 2 Django matches the request against its urls.py les. 3 If a match is found, Django moves on to the view that's associated with the URL. Views are generally found inside each app in the views.py le. 4 The view generally handles all the database manipulation. It grabs data and passes it on. 5 A template (specied in the view) then displays that data.

Site design in Django: review Goal: make common Web-development tasks fast Step 1: Design your model: model.py (M) Automatically create DB, APIs, admin interface Step 2: Design your views: views.py (V) Step 3: Design application logic: urls.py (C) Step 4: Design your templates: Step 5: Enjoy free bells & whistles (caching, syndication, ) 1/29/2013 CS 370, Spring 2012 5

Who cares? Spotify uses Django for some of their web sites. Instagram uses Django for their web application [10] Yandex uses Django for their weather forecast site, OpenID provider, blog hosting service, internal Wiki and internal Mail Archives. Transifex an open source platform for localization. Bucketlist uses Django to let users store life goals. The Public Broadcasting Service The Berkeley Graduate School of Journalism Universal Subtitles uses Django for its free and open source collaborative subtitling site. FreeNAS uses Django for its web interface in its 8.0 major release. PBS's Merlin, a platform for managing member stations' video metadata Google internal stuff (details unknown).. 1/24/2013 CS 370, Spring 2012 20

Example Django Project Tutorial: https://docs.djangoproject.com/en/dev/intro/tutorial01/ https://docs.djangoproject.com/en/dev/intro/tutorial03/ 1/29/2013 CS 370, Spring 2012 6

Django Models A model is the single, definitive source of data about your data. Each model is a Python class that subclasses django.db.models.model. Each attribute of the model represents a database field. Django gives you an automatically-generated database-access API 1/29/2013 CS 370, Spring 2012 7

Example: Person (first_name, last_name) Define Person: from django.db import models class Person(models.Model): first_name = models.charfield(max_length=30) last_name = models.charfield(max_length=30) What happens automatically CREATE TABLE myapp_person ( "id" serial NOT NULL PRIMARY KEY, "first_name" varchar(30) NOT NULL, "last_name" varchar(30) NOT NULL ); 1/29/2013 CS 370, Spring 2012 8

Example: Person (first_name, last_name): 2 Each field should be an instance of the Field class The database column type (e.g. INTEGER, VARCHAR) The widget to use in Django's admin interface, if you care to use it (e.g. <input type="text">, <select>). The minimal validation requirements, used in Django's automatically-generated forms. Field reference: https://docs.djangoproject.com/en/1.3/ref/models/fields/#model-field-types More details: https://docs.djangoproject.com/en/1.3/topics/db/models/ 1/29/2013 CS 370, Spring 2012 9

Django Models https://docs.djangoproject.com/en/dev/ref/models/instances/?from=olddocs 1/29/2013 CS 370, Spring 2012 10

Recap: Django project pieces django-admin.py startproject blog blog/ init.py: A file required for Python to treat the mysite directory as a package manage.py: A command-line utility that lets you interact with this project. Try: python manage.py help settings.py: Settings/configuration for this project. urls.py: The URLs for this project ( table of contents ) 1/29/2013 CS 370, Spring 2012 12

Django Project vs. App 1/29/2013 CS 370, Spring 2012 13

Django architecture encourages this 1/29/2013 CS 370, Spring 2012 14

Example: 1/29/2013 CS 370, Spring 2012 15

URL dispatcher A clean, elegant URL scheme is an important detail in a high-quality Web application. Django lets you design URLs however you want There s no.php or.cgi required Cool URIs don't change: http://www.w3.org/provider/style/uri 1/29/2013 CS 370, Spring 2012 16

How Django processes a request 1. Determine the root URLconf module to use. Ordinarily, this is the value of the ROOT_URLCONF setting, can be changed. 2. Load URLconf and looks for variable urlpatterns. This should be a Python list, in the format returned by the function django.conf.urls.patterns(). 3. Iterate through each URL pattern, in order, and stop at the first one that matches the requested URL. (REGEX) 4. If one of the regexes matches, import and call the given view, which is a Python function. The view gets passed an HttpRequest as its first argument and any values captured in the regex as remaining arguments. 5. If no regex matches, or if an exception is raised during any point in this process, invoke an appropriate error-handling view. 1/29/2013 CS 370, Spring 2012 17

Symbol Matches. (dot) Any single character \d Any single digit [A-Z] [a-z] [A-Za-z] 2-minute REGEX review Any character between A and Z (uppercase) Any character between a and z (lowercase) Any character between a and z (case-insensitive) + One or more of the previous expression (e.g., \d+ matches one or more digits) [^/]+ One or more characters until (and not including) a forward slash? Zero or one of the previous expression (e.g., \d? matches zero or one digits) Zero or more of the previous expression (e.g., \d* matches zero, one or more * than one digit) {1,3} http://www.djangoproject.com/r/python/re-module/ Between one and three (inclusive) of the previous expression (e.g., \d{1,3} matches one, two or three digits) 1/29/2013 CS 370, Spring 2012 18

Python Regexes, cont d To capture a value from the URL, just put parenthesis around it. There's no need to add a leading slash, because every URL has that. For example, it's ^wiki, not ^/wiki. The 'r' is optional but recommended. Named regular-expressions: (?P<name>pattern) (?P<page_name>[^/]+)/$', 1/29/2013 CS 370, Spring 2012 19

Example URLconf from django.conf.urls.defaults import * #http://cs370.mathcs.emory.edu:8100/wiki/csrf urlpatterns = patterns('', ) (r'^wiki/(?p<page_name>[^/]+)/$', 'blog.wiki.views.view_page'), (r'^wiki/(?p<page_name>[^/]+)/edit/$', 'blog.wiki.views.edit_page'), (r'^wiki/(?p<page_name>[^/]+)/save/$', 'blog.wiki.views.save_page'), 1/29/2013 CS 370, Spring 2012 20

Passing Parameters to Views

Good Design: Including other URLConfs Your urlpatterns can "include" other URLconf modules. Allows modular sites (good design) urlpatterns = patterns('', (r'^wiki/', include('blog.wiki.urls')) ) Note But: (wiki/urls.py): (r'^(?p<page_name>[^/]+)/$', 'blog.wiki.views.view_page') More details: https://docs.djangoproject.com/en/dev/topics/http/urls/ 1/29/2013 CS 370, Spring 2012 21

Design Pattern: Include URLs There should be one urls.py at the project level, and one urls.py at each app level. The project level urls.py should include each of the urls.py under a prefix.: http://agiliq.com/books/djangodesignpatterns/urls.html 1/29/2013 CS 370, Spring 2012 22

Django book: Onwards and upwords http://www.djangobook.com/en/2.0/ Common mistakes/gotchas: https://code.djangoproject.com/wiki/newbiemistakes To be continued 1/29/2013 CS 370, Spring 2012 29