UVa cs1120 David Evans Lecture 34: Djustifying Django.

Slides:



Advertisements
Similar presentations
Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 15 Introduction to Rails.
Advertisements

PHP I.
PHP II Interacting with Database Data. The whole idea of a database-driven website is to enable the content of the site to reside in a database, and to.
Cookies, Sessions. Server Side Includes You can insert the content of one file into another file before the server executes it, with the require() function.
/k/k 1212 Cascading Style Sheets Part one Marko Boon
End User Computing An Introduction to CSS Sujana Jyothi Research Lab1, Callan Building, Department of Computer Science
Stylin’ with CSS. 2 Topics What is CSS? Why CSS? CSS Examples.
Chapter 6 Basic forms 1. Forms and query string 2 form : a group of user input (UI) controls that accepts information from the user and sends the information.
Let’s try Oracle. Accessing Oracle The Oracle system, like the SQL Server system, is client / server. For SQL Server, –the client is the Query Analyser.
1 Chapter 12 Working With Access 2000 on the Internet.
Session 6 Server-side programming - ASP. An ASP page is an HTML page interspersed with server-side code. The.ASP extension instead of.HTM denotes server-side.
Session Management A290/A590, Fall /25/2014.
David Evans CS200: Computer Science University of Virginia Computer Science Class 29: Vocational Skills How to Build a.
INTRO TO MAKING A WEBSITE Mark Zhang.  HTML  CSS  Javascript  PHP  MySQL  …That’s a lot of stuff!
CS 174: Web Programming February 26 Class Meeting Department of Computer Science San Jose State University Spring 2015 Instructor: Ron Mak
PHP and SQL Server: Queries IST2101. Project Report 4 SQL Queries Due Sunday, 4/5 at 11:59pm Instructions on how to access team webspace and SQL database.
Christopher M. Pascucci Basic Structural Concepts of.NET Browser – Server Interaction.
Web Development Methodologies Yuan Wang(yw2326). Basic Concepts Browser/Server (B/S) Structure Keywords: Browser, Server Examples: Websites Client/Server.
ASHIMA KALRA.  INTRODUCTION TO JSP INTRODUCTION TO JSP  IMPLICIT OBJECTS IMPLICIT OBJECTS  COOKIES COOKIES.
Sys Prog & Scripting - HW Univ1 Systems Programming & Scripting Lecture 15: PHP Introduction.
Session 5: Working with MySQL iNET Academy Open Source Web Development.
Open Source Server Side Scripting ECA 236 Open Source Server Side Scripting Cookies & Sessions.
Copyright © Terry Felke-Morris WEB DEVELOPMENT & DESIGN FOUNDATIONS WITH HTML5 Chapter 3 Key Concepts 1 Copyright © Terry Felke-Morris.
건전지로 달리는 쟝고 세미나. 파트2 Last time MVC Views and URLconfs.
IT533 Lectures Session Management in ASP.NET. Session Tracking 2 Personalization Personalization makes it possible for e-businesses to communicate effectively.
Chapter 12 Cascading Style Sheets: Part II The Web Warrior Guide to Web Design Technologies.
Cascading Style Sheets Class 1, Lecture 1 Rachel A Ober
CSE 154 LECTURE 12: COOKIES. Including files: include include("filename"); PHP include("header.html"); include("shared-code.php"); PHP inserts the entire.
9 Chapter Nine Compiled Web Server Programs. 9 Chapter Objectives Learn about Common Gateway Interface (CGI) Create CGI programs that generate dynamic.
1 In the good old days... Years ago… the WWW was made up of (mostly) static documents. –Each URL corresponded to a single file stored on some hard disk.
Just A Few More Fun Objectives 1 Having Some Fun With Java Script 2 Using Style Sheets.
Java CGI Lecture notes by Theodoros Anagnostopoulos.
Web Programming Language Week 7 Dr. Ken Cosh Security, Sessions & Cookies.
Chapter 8 Cookies And Security JavaScript, Third Edition.
12/3/2012ISC329 Isabelle Bichindaritz1 PHP and MySQL Advanced Features.
Creating Dynamic Web Pages Using PHP and MySQL CS 320.
Agenda Architecture Overview Web Security Templates Templates and Style Sheets Details Configuring an Application Demo Summary.
ALBERT WAVERING BOBBY SENG. Week 2: HTML + CSS  Quiz  Announcements/questions/etc  Some functional HTML elements.
David Evans CS150: Computer Science University of Virginia Computer Science Lecture 22: Objectifying Objects.
CS 174: Web Programming September 30 Class Meeting Department of Computer Science San Jose State University Fall 2015 Instructor: Ron Mak
OWASP Top Ten #1 Unvalidated Input. Agenda What is the OWASP Top 10? Where can I find it? What is Unvalidated Input? What environments are effected? How.
Chapter 6 Server-side Programming: Java Servlets
Web Scripting [PHP] CIS166AE Wednesdays 6:00pm – 9:50pm Rob Loy.
CS216: Program and Data Representation University of Virginia Computer Science Spring 2006 David Evans Lecture 23: Review.
Google App Engine Data Store ae-10-datastore
Sessions in PHP – Page 1 of 13CSCI 2910 – Client/Server-Side Programming CSCI 2910 Client/Server-Side Programming Topic: Sessions in PHP Reading: Williams.
1 Theory, Practice & Methodology of Relational Database Design and Programming Copyright © Ellis Cohen Implementing The Middle Tier These slides.
Saving State on the WWW. The Issue  Connections on the WWW are stateless  Every time a link is followed is like the first time to the server — it has.
Dynamic Flash Images: Increased Functionality and Copy Protection for Online Images Jason W. Nadal.
David Evans CS200: Computer Science University of Virginia Computer Science Class 16: Mutation M. C. Escher, Day and Night.
8 Chapter Eight Server-side Scripts. 8 Chapter Objectives Create dynamic Web pages that retrieve and display database data using Active Server Pages Process.
1 State and Session Management HTTP is a stateless protocol – it has no memory of prior connections and cannot distinguish one request from another. The.
Creating Databases for Web Applications 3-Tier. Design vs Function vs Content. More SQL. More php. Homework: work on final projects.
1 PHP HTTP After this lecture, you should be able to know: How to create and process web forms with HTML and PHP. How to create and process web forms with.
21 Copyright © 2009, Oracle. All rights reserved. Working with Oracle Business Intelligence Answers.
Session 11: Cookies, Sessions ans Security iNET Academy Open Source Web Development.
David Evans CS200: Computer Science University of Virginia Computer Science Class 32: Vocational Skills (How to Build.
CS 440 Database Management Systems Stored procedures & OR mapping 1.
PHP: Further Skills 02 By Trevor Adams. Topics covered Persistence What is it? Why do we need it? Basic Persistence Hidden form fields Query strings Cookies.
PHP and SQL Server: Connection IST 210: Organization of Data IST2101.
111 State Management Beginning ASP.NET in C# and VB Chapter 4 Pages
CSS Introductions. Objectives To take control of the appearance of a Web site by creating style sheets. To use a style sheet to give all the pages of.
CS 330 Class 7 Comments on Exam Programming plan for today:
DBW - PHP DBW2017.
19.10 Using Cookies A cookie is a piece of information that’s stored by a server in a text file on a client’s computer to maintain information about.
PHP / MySQL Introduction
Class 29: Vocational Skills How to Build a Dynamic Web Site
Tutorial 10: Programming with javascript
PHP Forms and Databases.
Presentation transcript:

UVa cs1120 David Evans Lecture 34: Djustifying Django

Menu Django Innards Sign up for design reviews in class today Exam 2 Review Session: tonight, 6-7:30 in Olsson 001 Wednesday, 5-6:30pm, Olsson 228E: Fireside chat with Wes Weimer and Kim Hazelwood

Projects and Teams Project teams are posted on website Everyone should be happy with their team – if you’re not happy, let me know today! At the end of the project you will rate each of your teammates on: – Effort – Contribution – “Works well with others” All team members are responsible for the success of the project

MTV Programming ModelTemplate“View” Data Presentation How data is represented, accessed, and manipulated (defined by Python classes, automated by Django) Python programs for implementing application logic HTML templates for presenting output

Web Application Data Client (Browser) GET /overheardit HTTP/1.0 … … Contents of file Server HTTP protocol is stateless: each request is independent For data to persist across requests, needs to be either: stored on server (next: database) or embedded in request (later: cookies, form fields) For data to persist across requests, needs to be either: stored on server (next: database) or embedded in request (later: cookies, form fields)

Django Data Models class Story(models.Model): body = models.CharField(max_length=500) upvotes = models.IntegerField(default=0) orig_poster = models.CharField(max_length=15) post_date = models.DateTimeField('date published', auto_now=True) overheardit/stories/models.py: class variables: each instance gets its own copy (like an instance variable) that is assigned to real value or corresponding type

] python manage.py shell Python (r261:67517, Dec , 16:51:00)... >>> from overheardit.stories.models import Story >>> Story.objects.all() [, ] >>> import datetime >>> s = Story(body="I am the greatest!", upvotes=132, orig_poster="aph", post_date=datetime.datetime.now()) >>> s.id >>> s.save() >>> s.id 3 >>> s.body 'I am the greatest!' >>> s.body="I am the bestest!" >>> s.save() >>> s >>> Story.objects.all() [,, ] s is a instance of the Story class s.save() stores it in the database s is a instance of the Story class s.save() stores it in the database

SQL Structured Query Language – Developed by IBM (San Jose lab) in 1970s Standard language for interacting with databases – Database functions from PS5 were “inspired” by SQL (table-select bids 'item-name (lambda (pitem) (string=? pitem "CLAS"))) SELECT * FROM bids WHERE itemname = "CLAS"

Creating Tables (define bids (make-new-table (list 'bidder-name 'item-name 'amount)) CREATE TABLE bids ( "id" integer NOT NULL PRIMARY KEY, "bidder_name" NOT NULL varchar (50) "item_name" NOT NULL varchar (50) "amount" integer );

Another language to learn? No! Django (probably) automatically generates all the SQL you should need from Python code.

Django and Databases > python manage.py sqlall stories BEGIN; CREATE TABLE "stories_story" ( "id" integer NOT NULL PRIMARY KEY, "body" varchar(500) NOT NULL, "upvotes" integer NOT NULL, "orig_poster" varchar(15) NOT NULL, "post_date" datetime NOT NULL ) ; COMMIT; > python manage.py sqlall stories BEGIN; CREATE TABLE "stories_story" ( "id" integer NOT NULL PRIMARY KEY, "body" varchar(500) NOT NULL, "upvotes" integer NOT NULL, "orig_poster" varchar(15) NOT NULL, "post_date" datetime NOT NULL ) ; COMMIT; class Story(models.Model): body = models.CharField(max_length=500) upvotes = models.IntegerField(default=0) orig_poster = models.CharField(max_length=15) post_date = models.DateTimeField('date published', auto_now=True) overheardit/stories/models.py:

MTV Programming ModelTemplate“View” Data Presentation How data is represented, accessed, and manipulated (defined by Python classes, automated by Django) Python programs for implementing application logic HTML templates for presenting output

View def index(request): latest_story_list = Story.objects.all().order_by('-upvotes')[:20] return render_to_response('stories/index.html', {'latest_story_list' : latest_story_list, 'user' : request.user})}) overheardit/stories/views.py: class Story(models.Model): body = models.CharField(max_length=500) upvotes = models.IntegerField(default=0) orig_poster = models.CharField(max_length=15) post_date = models.DateTimeField('date published', auto_now=True) SELECT * FROM stories_story ORDER BY upvotes DESC LIMIT 20 SELECT * FROM stories_story ORDER BY upvotes DESC LIMIT 20 convert result (table) to a QuerySet object

More Complex Sorting def index(request): latest_story_list = list(Story.objects.all()[:20]) latest_story_list.sort(lambda s1, s2: cmp(s1.upvotes – s1.downvotes, s2.upvotes – s2.downvotes)) return render_to_response('stories/index.html', {'latest_story_list' : latest_story_list, 'user' : request.user}) convert the QuerySet into a Python list of Story objects

MTV Programming ModelTemplate“View” Data Presentation How data is represented, accessed, and manipulated (defined by Python classes, automated by Django) Python programs for implementing application logic HTML templates for presenting output

Connecting Data and Presentation def index(request): latest_story_list = Story.objects.all().order_by('-upvotes')[:20] return render_to_response('stories/index.html', {'latest_story_list' : latest_story_list, 'user' : request.user})}) render_to_response is a Django procedure that takes two inputs: - pathname to an HTML template - dictionary that defines variables for use in the template It processes the HTML template to produce the HTML output file, which will be sent back as the response. render_to_response is a Django procedure that takes two inputs: - pathname to an HTML template - dictionary that defines variables for use in the template It processes the HTML template to produce the HTML output file, which will be sent back as the response.

Template: templates/stories/index.html {% include "header.html" %} Post New Quotation {% if latest_story_list %} {% for story in latest_story_list %} Posted by {{story.orig_poster}} on {{story.post_date|date:"F j, Y"}} [up votes: {{story.upvotes}}] {{story.body}} Vote Up | Add Comment | {% load comments %} {% get_comment_count for story as comment_count %} View Comments ({{comment_count}}) {% endfor %} {% else %} No stories are available. {% endif %} {% include "footer.html" %} Blue: in {%... %} Commands interpreted by Django’s template processor Green: in {{... }} Variables from dictionary passed as second parameter Red: HTML...

Okay, so how do I change the colors? {% include "header.html" %}... templates/stories/index.html: templates/stories/header.html: {% include “style.html" %} Overheardit at UVa... templates/stories/style.html: #backdrop { padding:0; margin-left: 100px; margin-right: 100px; margin-top: 10px; background-color:#ffffff; font: calibri, helvetica, arial, sans-serif; } #header { height:60px; background-color:#980000; margin:auto; font: 300% calibri, helvetica, arial, sans-serif; text-align: center; color:#ffffff; } Defines the style of the bit RGB colors like in PS1! #RRGGBB Hexadecimal: 0-F FF = bit RGB colors like in PS1! #RRGGBB Hexadecimal: 0-F FF = 255 #FFFF00;

Wednesday’s Class Steve Huffman (UVa CS 2005) Co-founder (with Alexis Ohanian) of reddit Before Wednesday’s class: visit and try reddit.com

Charge Exam 2 Review Session: tonight, 6-7:30 in Olsson 001 Wednesday, 5-6:30pm, Olsson 228E: Fireside chat with Wes Weimer and Kim Hazelwood