Django Part II SPARCS 11 undead. Greatly Inspired by SPARCS 10 hodduc

Similar documents
MIT AITI Python Software Development Lab DJ1:

Django urls Django Girls Tutorial

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

정재성

django-intranet Documentation

WEB/DEVICE DEVELOPMENT CLIENT SIDE MIS/CIT 310

django-rest-framework-datatables Documentation

Django PAM Documentation

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

Building a Django Twilio Programmable Chat Application

A Sample Approach to your Project

DJOAuth2 Documentation

Django: Views, Templates, and Sessions

django-sekizai Documentation

django-baton Documentation

South Africa Templates.

Accelerating Information Technology Innovation

Building beautiful websites with Bootstrap: A case study. by Michael Kennedy michaelckennedy.net

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

django-baton Documentation

webkitpony Documentation

MapEntity Documentation

web frameworks design comparison draft - please help me improve it focus on Model-View-Controller frameworks

CSE 115. Introduction to Computer Science I

Google App Engine Using Templates

Lecture : 3. Practical : 2. Course Credit. Tutorial : 0. Total : 5. Course Learning Outcomes

Purpose of this doc. Most minimal. Start building your own portfolio page!

Djam Documentation. Release Participatory Culture Foundation

alphafilter Documentation

django-amp-tools Documentation Release latest

LECTURE 14. Web Frameworks

Quick.JS Documentation

TailorDev Contact Documentation

CS109 Data Science Data Munging

The starter app has a menu + 2 Views : Dashboard. About

Accelerating Information Technology Innovation

Berner Fachhochschule Haute école spécialisée bernoise Berne University of Applied Sciences 2

Without Django. applying django principles to non django projects

CSS (Cascading Style Sheets)

django-ad-code Documentation

Diving into Big Data Workshop

Web Programming and Design. MPT Senior Cycle Tutor: Tamara Week 1

NAVIGATION INSTRUCTIONS

CSCI 1320 Creating Modern Web Applications. Content Management Systems

The Structure of the Web. Jim and Matthew

Static Webpage Development

,.., «..»

django-session-security Documentation

Css Manually Highlight Current Link Nav Link

Intro, Version Control, HTML5. CS147L Lecture 1 Mike Krieger

django-xross Documentation

Django by errors. Release 0.2. Sigurd Gartmann

Django AdminLTE 2 Documentation

A designers guide to creating & editing templates in EzPz

Understanding this structure is pretty straightforward, but nonetheless crucial to working with HTML, CSS, and JavaScript.

django-scaffold Documentation

Django starting guide

Building a Python Flask Website A beginner-friendly guide

SCHOOL OF COMPUTING, ENGINEERING AND MATHEMATICS SEMESTER 2 EXAMINATIONS 2015/2016 CI135. Introduction to Web Development

django-templation Documentation

Responsive Web Design and Bootstrap MIS Konstantin Bauman. Department of MIS Fox School of Business Temple University

Mobile Design for the Future That is Here Already. Rick Ells UW Information Technology University of Washington

The Pyramid Web Application Development Framework

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

Front-End UI: Bootstrap

Django_template3d Documentation

MPT Web Design. Week 1: Introduction to HTML and Web Design

Let s Talk About Templates. Armin

Review of HTML. Chapter Pearson. Fundamentals of Web Development. Randy Connolly and Ricardo Hoar

CIS192 Python Programming

Django. Jinja2. Aymeric Augustin DjangoCong 2016

wagtailmenus Documentation

Quick housekeeping Last Two Homeworks Extra Credit for demoing project prototypes Reminder about Project Deadlines/specifics Class on April 12th Resul

Bootstrap 1/20

Quoting Wikipedia, software

Session 5. Web Page Generation. Reading & Reference

Moving to a Sustainable Web Development Environment for Library Web Applications

yawrap Documentation Release Michal Kaczmarczyk

Brief Intro to Firebug Sukwon Oh CSC309, Summer 2015

week8 Tommy MacWilliam week8 October 31, 2011

Static Site Generation

LECTURE 14. Web Frameworks

26 $host = "localhost" ; 27 $user = "marcolg" ; 28 $password = "" ; 52 $connessione = new mysqli ($host, $user, $password );

Project Part 2 (of 2) - Movie Poster And Actor! - Lookup

Announcements. 1. Class webpage: Have you been reading the announcements? Lecture slides and coding examples will be posted

Bookmarks to the headings on this page:

django cms Documentation

Flask-Genshi Documentation

webcore Documentation

Web Development and HTML. Shan-Hung Wu CS, NTHU

JavaScript: Objects, BOM, and DOM CS 4640 Programming Languages for Web Applications

django-cms-search Documentation

Code editor Django Girls Tutorial

Static Site Generation

introduction to XHTML

MODULE 2 HTML 5 FUNDAMENTALS. HyperText. > Douglas Engelbart ( )

HTML5: Adding Style. Styling Differences. HTML5: Adding Style Nancy Gill

Bambu Bootstrap Documentation

CS193X: Web Programming Fundamentals

Web development using PHP & MySQL with HTML5, CSS, JavaScript

Transcription:

Django Part II 2015-05-27 SPARCS 11 undead Greatly Inspired by SPARCS 10 hodduc

Previously on Django Seminar Structure of Web Environment HTTP Requests and HTTP Responses Structure of a Django Project Projects and applications How to Use Python Virtual Environments Simple views.py Urls.py URL Routing Dynamic URL (Regular Expression)

Today s Topic Templates Front end 코드연결하기 Reusing templates Django template tags, filters Basically all about Django template!

Template Languages for Designers (Front End Developers) Languages for Developers (Back End Developers) HTML CSS JavaScript ActionScript Python SQL JavaScript Go

Template Languages for Designers (Front End Developers) Language for Both Languages for Developers (Back End Developers) HTML CSS JavaScript ActionScript Django Template Python SQL JavaScript Go

Applying Templates Continue on Project Tutorial

Our Template <!DOCTYPE HTML> <html lang="ko"> <head> <meta charset="utf-8"> <title>django Seminar - Tutorial Project</title> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css"> <script src="//code.jquery.com/jquery-1.11.2.min.js"></script> <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js"></script> </head> <body> <nav class="navbar navbar-default"> <div class="container-fluid"> <div class="navbar-header"> <a class="navbar-brand" href="/">sparcs 2015 Django Seminar</a> </div> <div class="collapse navbar-collapse"> <ul class="nav navbar-nav"> <li class="dropdown"> <a href="/helloworld/" class="dropdown-toggle" data-toggle="dropdown" role="button" areaexpand="false">hello</span class="caret"></span></a> <ul class="dropdown-menu" role="menu"> <li><a href="/helloworld/helloworld/">world!</a></li> <li><a href="/helloworld/introduce/">me!</a></li> </ul> </li> <li><a href="/intro/">introduction</a></li> </ul> </div> </div> </nav> </body> </html>

Don t Panic! ~/ $ source env/bin/activate (env) ~/ $ cd tutorial (env) ~/tutorial $ mkdir templates (env) ~/tutorial $ wget https://raw.githubusercontent.com/shavakan/seminar_django/e2d 10704e0f92f85cd5c8aa7474ba68be6a34bce/tutorial/templates/base.html (env) ~/tutorial $ mv base.html templates/ (env) ~/tutorial $ ls templates/ base.html (env) ~/tutorial $ vi tutorial/settings.py

Set Template Directories # Set paths for HTML files. TEMPLATES = [ { DIRS : [ os.path.join(base_dir, templates ), ], }, ]

Add a Template (env) ~/tutorial $ vi helloworld/views.py from django.shortcuts import render def helloworld(request): return HttpResponse( Hello, World! ) def home(request): return render(request, base.html )

Adding a Template (env) ~/tutorial $ vi helloworld/urls.py urlpatterns = [ url(r ^$, helloworld.views.home ), url(r ^helloworld/, helloworld.views.helloworld ), url(r ^introduce/, helloworld.views.introduce ), ]

Adding a Template (env) ~/tutorial $ vi tutorial/urls.py from django.http import HttpResponseRedirect urlpatterns = [ url(r ^admin/, include(admin.site.urls)), url(r ^helloworld/, include( helloworld.urls )), url(r ^intro/, include( intro.urls )), url(r ^$, lambda r: HttpResponseRedirect( /helloworld/ )), ]

Adding a Template

Django Template

Similar Layouts

Similar Layouts

Similar Layouts

Similar Layouts

Similar Layouts

Similar Layouts

Similar Layouts

Similay Layouts Github Ara

{% extends something %} <base.html> <other.html> {% block content %} <!-- 기본으로보일내용 --> {% endblock %} {% extends base.html %} {% block content %} <!-- 덮어쓸내용 --> {% endblock %}

base.html </nav> {% block content %} <div class= container > This is the default page. Do Something :) </div> {% endblock %} </body> </html>

Extending HTML Files (helloworld) (env) ~/tutorial $ vi templates/helloworld.html {% extends base.html %} {% block content %} <div class= container > Hello, World! </div> {% endblock %}

Extending HTML Files (helloworld) (env) ~/tutorial $ vi helloworld/views.py def helloworld(request): return HttpResponse( Hello, World! ) return render(request, helloworld.html )

Extending HTML Files (introduce) (env) ~/tutorial $ vi templates/introduce.html {% extends base.html %} {% block content %} <div class= container > This is Shavakan, 24 years old, from Zul jin, Azeroth. </div> {% endblock %}

Extending HTML Files (env) ~/tutorial $ vi helloworld/views.py def introduce(request): return HttpResponse( This is Shavakan, 24 years old,\ from Zul jin, Azeroth. ) return render(request, introduce.html )

Extending HTML Files

Diff helloworld.html introduce.html <helloworld.html> <introduce.html> {% extends base.html } {% block content %} <div class= container > Hello, World! </div> {% endblock %} {% extends base.html } {% block content %} <div class= container > This is Shavakan, 24 years old, from Zul jin, Azeroth. </div> {% endblock %}

Diff helloworld.html introduce.html <helloworld.html> <introduce.html> {% extends base.html } {% block content %} <div class= container> Hello, World! </div> {% endblock %} {% extends base.html } {% block content %} <div class= container > This is Shavakan, 24 years old, from Zul jin, Azeroth. </div> {% endblock %}

Diff helloworld.html introduce.html <helloworld.html> <introduce.html> {% extends base.html } {% block content %} # Parts In Common {% endblock %} {% extends base.html } {% block content %} # Parts In Common {% endblock %}

Introducing JSON JavaScript Object Notation Key-Value Pair Syntax: { key1 : value1 }

Introducing JSON JavaScript Object Notation Key-Value Pair Syntax: { key1 : value1, key2 : value2, }

Introducing JSON JavaScript Object Notation Key-Value Pair Syntax: { key1 : value1, key2 : [ value2, value3, ], }

Using Template Variables Template Variables Passed in JSON form from views.py as a parameter of render() function (or equivalent other): { variable : value } Received in the following syntax from HTML files: {{ variable }}

Using Template Variables (env) ~/tutorial $ vi helloworld/views.py def helloworld(request): return render(request, helloworld.html, { message : Hello, World! }) def introduce(request): return render(request, introduce.html, helloworld.html, { message : This is Shavakan, 24 years old, from Zul\ jin, Azeroth. })

Using Template Variables (env) ~/tutorial $ rm templates/introduce.html (env) ~/tutorial $ vi templates/helloworld.html {% extends base.html } {% block content %} <div class= container> Hello, World! {{ message }} </div> {% endblock %}

Using Template Variables

Using Many Template Variables (env) ~/tutorial $ vi templates/base.html <li><a href= /helloworld/introduce/ >Me!</a></li> <li><a href= /helloworld/me/ >More Me!</a></li> </ul>

Using Many Template Variables More Me Tab screenshot

Using Many Template Variables <templates/me.html> <helloworld/views.py> <div class= container > <ul> <li>my name is {{name}}. </li> <li>my nickname is {{nickname}}. </li> <li>my hobby is {{hobby}}. </li> <li>my age is {{age}}. </li> <li>my relationship status is {{relationship}}. </li> </ul> </div> def me(request): ctx = { } name : ChangWon Lee, nickname : Shavakan, hobby : WoW, age : 24, relationship : single return render(resquest, me.html, ctx) # Edit helloworld/urls.py also!

Using Template Tag <me.html> <views.py> <div class= container > </li> <ul> <li>my name is {{name}}. </li> <li>my nickname is {{nickname}}. <li>my hobby is {{hobby}}. </li> <li>my age is {{age}}. </li> <li>my relationship status is {{relationship}}. </li> </div> </ul> def me(request): ctx = { name : ChangWon Lee, nickname : Shavakan, hobby : [ WoW, LOL, Hearthstone, Mabinogi, coding, taking a nap ], } age : 24, relationship : single return render(response, me.html, ctx)

Using Template Tag for-loop: {% for <var> in <list> %} {% endfor %}

Using Template Tag <me.html> <views.py> <div class= container > <ul> </li> <li>my name is {{name}}. </li> <li>my nickname is {{nickname}}. {% for h in hobby %} <li>my hobby is {{h}}. </li> {% endfor %} <li>my age is {{age}}. </li> <li>my relationship status is {{relationship}}. </li> </ul> </div> def me(request): ctx = { name : ChangWon Lee, nickname : Shavakan, hobby : [ WoW, LOL, Hearthstone, Mabinogi, coding, taking a nap ], } age : 24, relationship : single return render(response, me.html, ctx)

Using Template Tag <me.html> <views.py> <div class= container > <ul> <li>my name is {{name}}. </li> <li>my nickname is {{nickname}}. </li> {% for h in hobby %} <li>my hobby is {{ forloop.counter }} {{h}}. </li> {% endfor %} <li>my age is {{age}}. </li> <li>my relationship status is {{relationship}}. </li> </div> </ul> def me(request): ctx = { name : ChangWon Lee, nickname : Shavakan, hobby : [ WoW, LOL, Hearthstone, Mabinogi, coding, taking a nap ], } age : 24, relationship : single return render(response, me.html, ctx)

Using Template Tag if-statement: {% if <condition> %} {% else %} {% endif %}

Using Template Tag <me.html> <views.py> {% for h in hobby %} {% if h == coding %} <li>my hobby is {{ forloop.counter }} {{h}}. </li> {% else %} <li>my hobby is {{ forloop.counter}} SECRET. </li> {% endif %} {% endfor %} </ul> </div> def me(request): ctx = { name : ChangWon Lee, nickname : Shavakan, hobby : [ WoW, LOL, Hearthstone, Mabinogi, coding, taking a nap ], } age : 24, relationship : single return render(response, me.html, ctx)

List of Template Tags {% for some in some_list %} {% empty %} {% endfor %} {% if messages length >= 100 %} {% else %} {% block contents %} {% extends base.html %} <tr class= {% cycle black white %} > {% for data in list %} {% ifchanged year %} {{ data.year }} {% endifchanged %} {{ data.month }} / {{ data.date }} {% endfor %} {% ifequal user.username shavakan %} {% endifequal %} 오늘은 {% now js F Y H:I %} 입니다. (and more )

List of Template Filters {{ value add: 2 }} 3 -> 5 {{ value center: 15 }} hello -> hello {{ value cut: }} I love you -> Iloveyou {{ value default: 없ㅋ엉ㅋ }} {{ htmlvalue escape }} {{ capacity filesizeformat }} 123456789 -> 117.7 MB {{ value join: // }} [ a, b, c ] -> a // b // c {{ value random }} [ a, b, c ] ->?? {{ value title }} i love you -> I Love You {{ value last }} ABCDEFG -> G {{ value stringformat: s }} {{ value random title }} (and more )

Today s Practice: Introduction Relay 당신은누구십니까? Modify /intro/ Modify /intro/<str>/<str>/<str>/ http://bit.sparcs.org:10000/intro/ 나는 [ A ] [ B ] 의 [ C ] 입니다. <Go!> <Go!> 를클릭하면 /intro/a/b/c/ 로이동! http://bit.sparcs.org:10000/intro/a/b/c/ 나는 A B 의 C 입니다. 나는 [ A ] [ B ] 의 [ C ] 입니다. <Go!>

Today s Practice: Introduction Relay 주의사항 : 두 URL 에대하여 html 파일은반드시한개만사용하여야함 입력창이두 URL 에모두존재하여야함 참고코드 : https://gist.githubusercontent.com/shavakan/57b8511ad16ca1 d7c254/raw/9c40c1ca6e149b10112fe0f99ddbe18becff1deb/gis tfile1.txt

Today s Practice: Hello, Ahaes! http://bit.sparcs.org:10000/helloworld/ahae/1024/ 1024인의아해가도로를질주하오. 제1의아해가무섭다고그리오. 제2의아해가무섭다고그리오. 제1023의아해가무섭다고그리오. 제1024의아해가무서운아해와무서워하는아해와그렇게뿐이모였소. ( 다른사정은없는것이차라리나았소.) 그중에1인의아해가무서운아해라해도좋소. 그중에102인의아해가무서운아해라해도좋소. 그중에102인의아해가무서운아해라해도좋소. 그중에1인의아해가무서운아해라해도좋소. ( 길은뚫린골목이라도적당하오.) 1024인의아해가도로로질주하지아니하여도좋소.