Add part 4b, views showing object data

parent f6884a7c
......@@ -95,3 +95,6 @@ Part 4
Add default view.
Edit `urlapp/views.py`, create `urlapp/urls.py`.
Edit `redurl/urls.py`.
Make views that do something, just reading the objects' data.
from django.shortcuts import render
from django.http import HttpResponse
from .models import Url
# Create your views here.
def index(request):
return HttpResponse("Hello, world!")
L = Url.objects.all()
output = ', '.join([u.target for u in L])
return HttpResponse(output)
def redir(request, url_id):
return HttpResponse("You're following URL {}.".format(url_id))
def url(request, url_id):
return HttpResponse("You're looking at URL {}.".format(url_id))
u = Url.objects.get(id=url_id)
return HttpResponse("URL {} goes to {}.".format(url_id, u.target))
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment