Add part 4a, simple views

parent eb3596a7
...@@ -89,3 +89,9 @@ Remove the `User` model and replace with that in `django.contrib.auth.models`. ...@@ -89,3 +89,9 @@ Remove the `User` model and replace with that in `django.contrib.auth.models`.
python manage.py makemigrations urlapp python manage.py makemigrations urlapp
python manage.py migrate python manage.py migrate
Part 4
------
Add default view.
Edit `urlapp/views.py`, create `urlapp/urls.py`.
Edit `redurl/urls.py`.
...@@ -17,5 +17,6 @@ from django.conf.urls import include, url ...@@ -17,5 +17,6 @@ from django.conf.urls import include, url
from django.contrib import admin from django.contrib import admin
urlpatterns = [ urlpatterns = [
url(r'^', include('urlapp.urls')),
url(r'^admin/', include(admin.site.urls)), url(r'^admin/', include(admin.site.urls)),
] ]
from django.conf.urls import url
from . import views
urlpatterns = [
url(r'^$', views.index, name='index'),
url(r'^(?P<url_id>[0-9]+)/$', views.redir, name='redir'),
url(r'^url=(?P<url_id>[0-9]+)/$', views.url, name='url'),
]
from django.shortcuts import render from django.shortcuts import render
from django.http import HttpResponse
# Create your views here. # Create your views here.
def index(request):
return HttpResponse("Hello, world!")
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))
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