SlideShare a Scribd company logo
Introduction to
Web Development
CDL
23.03.2014 alex@rosedu.org
mtiriplica@rosedu.org
Summary
● HTTP
● Anatomy of a web app
● ORM
● Frontend
● Flask workshop
Server
● aplicație
● mașină (un calculator)
● așteaptă cereri
● răspunde la cereri
Client
● aplicație
● face cereri
● așteaptă răspunsuri
● interpretează răspunsuri
HTTP… Whaaat?
● Protocol de comunicație (boooring)
● Baza WWW
● Folosit de API-uri (What’s an API?)
HTTP Requests
● CRUD
● GET
● POST
● PUT
● DELETE
● HEAD
● PATCH
HTTP Response Codes
● 200+
● 300+
● 400+
● 500+
HTTP Sessions
● Schimb de informatii intre doua entitati
● request + response
● Cookies - sesiuni persistente
Anatomy of a web app
Asynchronous requests
URI
Views
Logic
Data
Resources
Presentation
URLs and Views
http://localhost:5000/account/settings/
def settings():
method = request.method
return “Salut ” + method
SQL
● Structured Query Language, pron: sicuăl
○ tables, columns and rows
○ select * from table
○ insert into table
○ update table
○ delete from table
● Object Relational Model
○ each table is a class
○ each row is an object
○ backrefs: one to many, many to many relations
Backref Magic
● usual db code:
select * from books where author_id=1
select name from authors where author_id=1
select b.*, a.name from books b
left join authors a on b.author_id=a.id
where a.id=1
● models:
class Author:
name = String
class Book:
author = FK(Author, backref=’books’)
x = Author(name=’Tiri’)
y = Book(author=x)
x.books
y.author.name
Frontend (Not just for designers)
● HTML
● CSS
● Javascript
● For hipsters: Brython
HTML
● versiunea 5
● tag-uri:
<h3>I am a header </h3>
<h2> No, I am header!</h2>
<p> Stop it!</p>
DOM
● reprezentarea și interacționarea cu elemente
HTML
● structură de arbore
CSS
CSS
● Dă stil codului HTML:
p {
font-size: 1.2em;
line-height: 1.0em;
color: #333;
width: 100%;
}
Javascript
● Pagini web dinamice
var getMaxHeight = function ($elms) {
var maxHeight = 0;
$elms.each(function () {
var height = $(this).height();
if (height > maxHeight) {
maxHeight = height;
}
});
return maxHeight;
};
Must Know
● Bootstraps: http://getbootstrap.com/2.3.2/
● jQuery - manipulare de elemente din DOM
Workshop time!
● Setup environment
● Write simple web app
● Add templates
● Make a form
● Add some javascript
● Profit!
Virtualenv
# install system-wide
apt-get install python-virtualenv
# create new
virtualenv env
# activate
source env/bin/activate
# install flask
pip install flask
# pip freeze
pip freeze > requirements.txt
webapp.py
import flask
app = flask.Flask(__name__)
app.config['DEBUG'] = True
@app.route('/')
def home():
return "Hello World!"
if __name__ == '__main__':
app.run()
Then, in a terminal:
$ python webapp.py
Open in browser: http://localhost:5000/
templates/home.html:
<html>
<body>
<h1>Hello World</h1>
&copy; CDL 2014
</body>
</html>
templates/other.html
<html>
<body>
<h1>Goodbye World</h1>
&copy; CDL 2014
</body>
</html>
templates/layout.html
<html>
<body>
{% block content %}
{% endblock %}
&copy; CDL 2014
</body>
</html>
templates/home.html*:
{% extends ‘layout.html’ %}
{% block content %}
<h1>Hello world!</h1>
{% endblock %}
Misc
webapp.py:
...
return render_template(‘home.html’, {name=’alex’})
home.html:
...
Hello {{ name }}!
Hello {{ name|capitalize }}
Go <a href=”{{ url_for(‘.form) }}”>form</a>!
Form
webapp.py:
@app.route(‘/form’, methods=[‘GET’, ‘POST’])
def form():
if flask.request.method == ‘POST’:
print “Received: ”, flask.request.form
return flask.render_template(‘form.html’)
templates/form.html:
...
<form method=”POST” action=”/form”>
<input type=”text” name=”message” value=”” id=”msg" />
<button type=”submit”>Send message!</button>
</form>
Javascript
webapp.py:
@app.route(‘/default-message’)
def dm():
return “This is a placeholder”
templates/form.html:
<button id=”but”>Set default text</button>
Javascript (continued)
templates/form.html:
<script src="http://code.jquery.com/jquery-1.11.0.min.js">
</script>
<script>
$("#but").click(function(event) {
event.preventDefault();
$.ajax({
url: "/default-message",
}).done(function(result) {
$("#msg").val(result);
});
});
</script>
TODOs
● Toate elementele <h1> trebuie să aibă culoarea verde
si dimesiunea fontului 40px
● Butonul de submit trebuie să aibă lungimea de 500px,
iar atunci când mouse-ul este deasupra lui trebuie să își
schimbe culoarea
● Adăugați un nou view ce corespunde url-ului ‘/login’.
Pagina afișată trebuie să conțină câmpuri pentru nume
și parolă și un buton de Log In. După submit, va afișa
un alt template.
Alte resurse
CSS Reference
Javascript refernce
Prezentare Flask

More Related Content

PDF
Flask intro - ROSEdu web workshops
KEY
Building a real life application in node js
PPT
Php basic for vit university
PDF
Rails GUI Development with Ext JS
PPTX
Express js
PDF
Hash Signaling Made Easy
PPTX
Building Web Apps with Express
PDF
Asynchronous PHP and Real-time Messaging
Flask intro - ROSEdu web workshops
Building a real life application in node js
Php basic for vit university
Rails GUI Development with Ext JS
Express js
Hash Signaling Made Easy
Building Web Apps with Express
Asynchronous PHP and Real-time Messaging

What's hot (20)

PDF
Understanding the Node.js Platform
PDF
Introduction to Nodejs
PDF
Javascript
PDF
Introduction to Node.js
PDF
Django Rest Framework and React and Redux, Oh My!
PDF
AJAX Transport Layer
PDF
Web Components With Rails
PDF
Introduzione JQuery
PDF
Java script tutorial
PDF
"The little big project. From zero to hero in two weeks with 3 front-end engi...
PDF
Even faster django
PDF
Pragmatic Browser Automation with Geb - GIDS 2015
PDF
Mojolicious
PDF
Building com Phing - 7Masters PHP
PDF
Express node js
PDF
Learning django step 1
PDF
HTTP Caching and PHP
PPTX
Introduction to Vert.x
PDF
Moodle 3.3 - API Change Overview #mootieuk17
PPTX
Node.js Express
Understanding the Node.js Platform
Introduction to Nodejs
Javascript
Introduction to Node.js
Django Rest Framework and React and Redux, Oh My!
AJAX Transport Layer
Web Components With Rails
Introduzione JQuery
Java script tutorial
"The little big project. From zero to hero in two weeks with 3 front-end engi...
Even faster django
Pragmatic Browser Automation with Geb - GIDS 2015
Mojolicious
Building com Phing - 7Masters PHP
Express node js
Learning django step 1
HTTP Caching and PHP
Introduction to Vert.x
Moodle 3.3 - API Change Overview #mootieuk17
Node.js Express
Ad

Similar to Introducere in web (8)

PPTX
Bootstrap basics.pptx of web design responsive design
PDF
Web05 dezvoltareaaplicatiilorweb php
PDF
Introduction to Flask Micro Framework
PDF
Web Server and how we can design app in C#
PPTX
221c82d4-5428-4047-8558-0467b34083e8.pptx
PDF
Resume Zhuoyuan Lin(Leon)
PDF
Practical Web Development 1st Edition Wellens Paul
PPTX
Node.js, From Simple to Complex
Bootstrap basics.pptx of web design responsive design
Web05 dezvoltareaaplicatiilorweb php
Introduction to Flask Micro Framework
Web Server and how we can design app in C#
221c82d4-5428-4047-8558-0467b34083e8.pptx
Resume Zhuoyuan Lin(Leon)
Practical Web Development 1st Edition Wellens Paul
Node.js, From Simple to Complex
Ad

More from Alex Eftimie (7)

PDF
ROSEdu - Starea comunității
PDF
Introducere în Linux
PDF
Django Celery - A distributed task queue
PDF
Prezentare raport de cercetare
PDF
LabRemote - Web in Progress
PDF
Diploma Presentation
PPT
Lucruri noi in MPI-2
ROSEdu - Starea comunității
Introducere în Linux
Django Celery - A distributed task queue
Prezentare raport de cercetare
LabRemote - Web in Progress
Diploma Presentation
Lucruri noi in MPI-2

Recently uploaded (20)

PDF
Insiders guide to clinical Medicine.pdf
PDF
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
PPTX
Microbial diseases, their pathogenesis and prophylaxis
PDF
102 student loan defaulters named and shamed – Is someone you know on the list?
PDF
RMMM.pdf make it easy to upload and study
PDF
Pre independence Education in Inndia.pdf
PPTX
Institutional Correction lecture only . . .
PPTX
Pharma ospi slides which help in ospi learning
PDF
STATICS OF THE RIGID BODIES Hibbelers.pdf
PDF
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
PDF
Abdominal Access Techniques with Prof. Dr. R K Mishra
PDF
Sports Quiz easy sports quiz sports quiz
PPTX
Pharmacology of Heart Failure /Pharmacotherapy of CHF
PDF
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
PDF
Microbial disease of the cardiovascular and lymphatic systems
PDF
Anesthesia in Laparoscopic Surgery in India
PDF
2.FourierTransform-ShortQuestionswithAnswers.pdf
PDF
O7-L3 Supply Chain Operations - ICLT Program
PDF
Classroom Observation Tools for Teachers
PDF
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
Insiders guide to clinical Medicine.pdf
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
Microbial diseases, their pathogenesis and prophylaxis
102 student loan defaulters named and shamed – Is someone you know on the list?
RMMM.pdf make it easy to upload and study
Pre independence Education in Inndia.pdf
Institutional Correction lecture only . . .
Pharma ospi slides which help in ospi learning
STATICS OF THE RIGID BODIES Hibbelers.pdf
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
Abdominal Access Techniques with Prof. Dr. R K Mishra
Sports Quiz easy sports quiz sports quiz
Pharmacology of Heart Failure /Pharmacotherapy of CHF
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
Microbial disease of the cardiovascular and lymphatic systems
Anesthesia in Laparoscopic Surgery in India
2.FourierTransform-ShortQuestionswithAnswers.pdf
O7-L3 Supply Chain Operations - ICLT Program
Classroom Observation Tools for Teachers
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx

Introducere in web