From d84d7d9823da9c7e9a71ad7d92ea30bfcf0037eb Mon Sep 17 00:00:00 2001 From: Ambulance Clerc Date: Mon, 20 Dec 2021 18:46:18 +0100 Subject: [PATCH] End tuto03 --- CppProperties.json | 21 +++++++++++++++++++++ polls/templates/polls/detail.html | 6 ++++++ polls/templates/polls/index.html | 10 ++++++++++ polls/urls.py | 7 +++++++ polls/views.py | 26 +++++++++++++++++++++++--- 5 files changed, 67 insertions(+), 3 deletions(-) create mode 100644 CppProperties.json create mode 100644 polls/templates/polls/detail.html create mode 100644 polls/templates/polls/index.html diff --git a/CppProperties.json b/CppProperties.json new file mode 100644 index 0000000..659bf4e --- /dev/null +++ b/CppProperties.json @@ -0,0 +1,21 @@ +{ + "configurations": [ + { + "inheritEnvironments": [ + "msvc_x86" + ], + "name": "x86-Debug", + "includePath": [ + "${env.INCLUDE}", + "${workspaceRoot}\\**" + ], + "defines": [ + "WIN32", + "_DEBUG", + "UNICODE", + "_UNICODE" + ], + "intelliSenseMode": "windows-msvc-x86" + } + ] +} \ No newline at end of file diff --git a/polls/templates/polls/detail.html b/polls/templates/polls/detail.html new file mode 100644 index 0000000..0d2aa3e --- /dev/null +++ b/polls/templates/polls/detail.html @@ -0,0 +1,6 @@ +

{{ question.question_txt }}

+ \ No newline at end of file diff --git a/polls/templates/polls/index.html b/polls/templates/polls/index.html new file mode 100644 index 0000000..e83e988 --- /dev/null +++ b/polls/templates/polls/index.html @@ -0,0 +1,10 @@ +{% if latest_question_list %} +

Liste des questions:

+ +{% else %} +

No polls are available.

+{% endif %} \ No newline at end of file diff --git a/polls/urls.py b/polls/urls.py index 0f1dbbd..93ad135 100644 --- a/polls/urls.py +++ b/polls/urls.py @@ -3,6 +3,13 @@ from django.urls import path from . import views +app_name = "polls" urlpatterns = [ path('',views.index, name='index'), + # ex: /polls/5/ + path('specifics//', views.detail, name='detail'), + # ex: /polls/5/results/ + path('/results/', views.results, name='results'), + # ex: /polls/5/vote/ + path('/vote/', views.vote, name='vote'), ] \ No newline at end of file diff --git a/polls/views.py b/polls/views.py index e51e982..200230e 100644 --- a/polls/views.py +++ b/polls/views.py @@ -1,6 +1,26 @@ -from django.shortcuts import render +from django.shortcuts import get_object_or_404, render +from django.http import Http404 from django.http import HttpResponse + +from polls.models import * + def index(request): - return HttpResponse("Hello, world kirosbr ! test 2") -# Create your views here. + latest_question_list = Question.objects.order_by("-pub_date")[:5] + + context = { + "latest_question_list": latest_question_list, + } + + return render(request, 'polls/index.html', context) + +def detail(request, question_id): + question = get_object_or_404(Question, pk=question_id) + return render(request, 'polls/detail.html', {'question': question}) + +def results(request, question_id): + response = "You're looking at the results of question %s." + return HttpResponse(response % question_id) + +def vote(request, question_id): + return HttpResponse("Tu réponds à la question %s." % question_id)