Slide 1

Slide 1 text

AceleraDev Loadsmart Women Edition Módulo 4 Camila Maia

Slide 2

Slide 2 text

Esta apresentação está disponível em: https://github.com/camilamaia/acelera-dev-loadsmart-women/

Slide 3

Slide 3 text

list e dict comprehensions, map, reduce, filter... Django REST Framework Módulos

Slide 4

Slide 4 text

● Hyper Text Markup Language ● HTML é a linguagem usada para criação de sites. Tem como função exibir as informações. ● A base do HTML são suas tags e atributos. HTML

Slide 5

Slide 5 text

● Conjunto de caracteres que formam elementos ● São a representação de um elemento html ● Browsers do not display the HTML tags, but use them to render the content of the page Exemplos: ●

,

, , Most tags must be opened

and closed

in order to function. HTML Tags

Slide 6

Slide 6 text

No content

Slide 7

Slide 7 text

No content

Slide 8

Slide 8 text

● Informações passadas dentro da Tag para que ela se comporte da maneira esperada Exemplos: ● class, id, href, src HTML Atributos

Slide 9

Slide 9 text

● CSS é a linguagem usada para estilizar uma página HTML. ● No CSS são definidas cores, fontes, margens, etc. CSS

Slide 10

Slide 10 text

No content

Slide 11

Slide 11 text

No content

Slide 12

Slide 12 text

● Descreve qual dado será apresentado ● A view is simply a Python function that takes a Web request and returns a Web response ● This response can be the HTML contents of a Web page, or a redirect, or a 404 error, or an XML document, or an image . . . or anything, really ● The view itself contains whatever arbitrary logic is necessary to return that response View

Slide 13

Slide 13 text

View VIEW HTTP request HTTP response

Slide 14

Slide 14 text

Function Based Views Sempre retornando uma HTTP Response

Slide 15

Slide 15 text

● Nomes para as urls são importantes! ○ Refactoring ○ Evitar urls quebradas Function Based Views

Slide 16

Slide 16 text

● Class-based views provide an alternative way to implement views as Python objects instead of functions. ● They do not replace function-based views ● Reutilizar código através de: ○ Heranças ○ Mixins ● Não precisar fazer um branch de if’s Class Based Views

Slide 17

Slide 17 text

Class Based Views Sempre retornando uma HTTP Response

Slide 18

Slide 18 text

● Django já provê uma série de classes e mixins para serem utilizados ● ListView ● DetailView ● UpdateView ● CreateView ● DeleteView Class Based Generic Views

Slide 19

Slide 19 text

FBVs ou CBVs? https://www.twoscoopspress.com/products/two-scoops-of-django-1-11

Slide 20

Slide 20 text

No content

Slide 21

Slide 21 text

Django Templates ● Django is a web framework ● Django helps to generate HTML dynamically

Slide 22

Slide 22 text

No content

Slide 23

Slide 23 text

Django Templates static parts of the desired HTML output + some special syntax describing how dynamic content will be inserted.

Slide 24

Slide 24 text

Django Template Language (DTL) ● Variables ○ {{variable}} ● Filters ● Tags ○ if ○ for ○ block / extends ○ comment Django Templates

Slide 25

Slide 25 text

● Render Function ○ Request − The initial request. ○ The path to the template − This is the path relative to the TEMPLATE_DIRS option in the project settings.py variables. ○ Dictionary of parameters − A dictionary that contains all variables needed in the template. This variable can be created or you can use locals() to pass all local variable declared in the view. Django Templates

Slide 26

Slide 26 text

Django Templates

Slide 27

Slide 27 text

Django Forms ● Django provides a range of tools and libraries to help you build forms to accept input from site visitors, and then process and respond to the input.

Slide 28

Slide 28 text

● A form is a collection of elements inside ... ● Forms allow a visitor to do things like: ○ Enter text, ○ Select options, ○ Manipulate objects or controls, ○ … ● Then send that information back to the server. HTML Forms

Slide 29

Slide 29 text

● Action ○ The action attribute defines the action to be performed when the form is submitted. ● Input ○ The element can be displayed in several ways, depending on the type attribute. https://www.w3schools.com/html/tryit.asp?filename=try html_form_radio https://www.w3schools.com/html/tryit.asp?filename=try html_form_submit HTML Forms

Slide 30

Slide 30 text

HTML Forms ● Method ○ The method attribute specifies the HTTP method (GET or POST) to be used when submitting the form data https://www.w3schools.com/html/tryit.asp?filename=try html_form_get https://www.w3schools.com/html/tryit.asp?filename=try html_form_post

Slide 31

Slide 31 text

Como queremos

Slide 32

Slide 32 text

Forms

Slide 33

Slide 33 text

Django Forms ● A Form instance has an is_valid() method, which runs validation routines for all its fields. ● When this method is called, if all fields contain valid data, it will: ○ return True ○ place the form’s data in its cleaned_data attribute.

Slide 34

Slide 34 text

Note that it does not include the tags, or a submit button. We’ll have to provide those ourselves in the template. Rendered

Slide 35

Slide 35 text

View

Slide 36

Slide 36 text

Template

Slide 37

Slide 37 text

Models e Forms ● Null -- Banco de Dados ○ Default is False ● Blank -- Forms ○ Default is False

Slide 38

Slide 38 text

null=True blank=True

Slide 39

Slide 39 text

null=True blank=True

Slide 40

Slide 40 text

Dúvidas?

Slide 41

Slide 41 text

Aprendi muita coisa nova! Conhecimento Passado Conhecimento: 0-10 Legal, mas não aprendi nada novo, não.

Slide 42

Slide 42 text

Muito rápido, tô assimilando o primeiro slide ainda. Velocidade Velocidade: 0-10 ZzzZzzz, pode acelerar isso aí. 5: Velocidade ideal.

Slide 43

Slide 43 text

Conteúdos ● https://www.tutorialspoint.com/django/django_template_system.htm ● https://docs.djangoproject.com/en/2.1/topics/forms/ ● https://docs.djangoproject.com/en/2.1/topics/templates/ ● https://www.twoscoopspress.com/products/two-scoops-of-django-1-11 ● https://docs.djangoproject.com/en/2.1/topics/class-based-views/generic-d isplay/ ● https://docs.djangoproject.com/en/2.1/topics/class-based-views/ ● https://easyaspython.com/mixins-for-fun-and-profit-cb9962760556 ● https://djangobook.com/user-authentication-django/ ● https://www.w3schools.com/html/html_intro.asp ●

Slide 44

Slide 44 text

MUITO OBRIGADA!