Skip to content
Open

lala #13

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions home/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from . import views

urlpatterns = [
path('home', views.home),
path('authorized', views.authorized),
urlpatterns = [
path('home/', views.HomeView.as_view(), name='home'),
path('authorized/', views.AuthorizedView.as_view(), name='authorized')
]
19 changes: 13 additions & 6 deletions home/views.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
from django.shortcuts import render
from django.http import HttpResponse
from datetime import datetime
from django.contrib.auth.decorators import login_required
from django.views.generic import TemplateView
from django.contrib.auth.mixins import LoginRequiredMixin

def home(request):
return render(request, 'home/welcome.html', {'today': datetime.today()})

@login_required(login_url='/admin')
def authorized(request):
return render(request, 'home/authorized.html', {})
# Class based views
class HomeView(TemplateView):
template_name = 'home/welcome.html'

extra_context = {
'today': datetime.today()
}

class AuthorizedView(TemplateView):
template_name = 'home/authorized.html'
login_url = '/admin'
4 changes: 2 additions & 2 deletions notes/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
from . import views

urlpatterns = [
path('notes', views.list),
path('notes/<int:pk>', views.detail),
path('notes/', views.NotesListView.as_view(), name='notes_list'),
path('notes/<int:pk>', views.NotesDetailView.as_view(), name='notes_detail'),
]
22 changes: 12 additions & 10 deletions notes/views.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
from django.shortcuts import render
from django.http import Http404

from django.views.generic import ListView, DetailView
from .models import Notes

def list(request):
all_notes = Notes.objects.all()
return render(request, 'notes/notes_list.html', {'notes': all_notes})

def detail(request, pk):
try:
note = Notes.objects.get(pk=pk)
except Notes.DoesNotExist:
raise Http404("This note doesn't exist")
return render(request, 'notes/notes_detail.html', {'note': note})
class NotesListView(ListView):
model = Notes
context_object_name = "notes"
template_name = "notes/notes_list.html"


class NotesDetailView(DetailView):
model = Notes
context_object_name = "note"
template_name = "notes/notes_detail.html"