Views Flashcards

1
Q

simple response

A

from django.http import HttpResponse

return HttpResponse(“Hello there friend!”)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

pass in variable into template

A
def home(request):
    return render(request, 'generator/home.html',{"password": "abc1234"})

{{password}} in the html

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

render function (3 pieces)

A
  1. request
  2. templates folder (without the “template)
  3. a dictionary
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

import data

A

from .models import MyClass

projects = Project.objects.all()
# grab all objects

return render(request, “portfolio/home.html”, {‘projects’:projects,})

put in a dict, don’t forget the comma at the end; key has to be the same as well

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

when to use {{ abc }}

A

like pulling a variable

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

when to use {% %}

A
  1. URL
  2. iterations
    {% for abc in projects %}

{% endfor %}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly