Views Flashcards
1
Q
simple response
A
from django.http import HttpResponse
return HttpResponse(“Hello there friend!”)
2
Q
pass in variable into template
A
def home(request): return render(request, 'generator/home.html',{"password": "abc1234"})
{{password}} in the html
3
Q
render function (3 pieces)
A
- request
- templates folder (without the “template)
- a dictionary
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
5
Q
when to use {{ abc }}
A
like pulling a variable
6
Q
when to use {% %}
A
- URL
- iterations
{% for abc in projects %}
{% endfor %}