Dedicated Home View

This commit is contained in:
reverend 2020-08-03 19:14:37 +02:00
parent b54e81d372
commit 049b672c00
3 changed files with 12 additions and 1 deletions

View File

@ -24,7 +24,6 @@ from django.urls import path, include
from django.views.generic.base import TemplateView from django.views.generic.base import TemplateView
urlpatterns = [ urlpatterns = [
path('', TemplateView.as_view(template_name='home.html'), name='home'),
path('admin/', admin.site.urls), path('admin/', admin.site.urls),
path('explorers/', include('django.contrib.auth.urls')), path('explorers/', include('django.contrib.auth.urls')),
path('', include('lostplaces_app.urls')), path('', include('lostplaces_app.urls')),

View File

@ -1,6 +1,7 @@
from django.urls import path from django.urls import path
from .views import ( from .views import (
hello_world, hello_world,
HomeView,
place_detail_view, place_detail_view,
place_list_view, place_list_view,
SignUpView, SignUpView,
@ -10,6 +11,7 @@ from .views import (
urlpatterns = [ urlpatterns = [
path('hello_world/', hello_world), # You know what this is :P path('hello_world/', hello_world), # You know what this is :P
path('', HomeView.as_view(), name='home'),
path('signup/', SignUpView.as_view(), name='signup'), path('signup/', SignUpView.as_view(), name='signup'),
path('place/<int:pk>/', place_detail_view, name='place_detail'), path('place/<int:pk>/', place_detail_view, name='place_detail'),
path('place/create/', PlaceCreateView.as_view(), name='place_create'), path('place/create/', PlaceCreateView.as_view(), name='place_create'),

View File

@ -28,6 +28,16 @@ def place_detail_view(request, pk):
def hello_world(request): def hello_world(request):
return render(request, 'hello_world.html', {'text':'Hello World!'}) return render(request, 'hello_world.html', {'text':'Hello World!'})
class HomeView(View):
def get(self, request, *args, **kwargs):
place_list = Place.objects.all().order_by('submitted_when')[:10]
print(place_list)
context = {
'place_list': place_list
}
return render(request, 'home.html', context)
class PlaceUpdateView(UpdateView): class PlaceUpdateView(UpdateView):
template_name = 'update_place.html' template_name = 'update_place.html'
model = Place model = Place