Skip to content

Instantly share code, notes, and snippets.

@selimhamidou
Last active June 11, 2020 16:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save selimhamidou/940bf87d06c8c6633a5ea296e2798cba to your computer and use it in GitHub Desktop.
Save selimhamidou/940bf87d06c8c6633a5ea296e2798cba to your computer and use it in GitHub Desktop.
<form method = "POST" action="resultat.html"> {% csrf_token %}
{{ form }}
<input type = "submit" value = "Submit">
</form>
<h1>Resultat</h1>
<!--{{form}}-->
from . import views
from django.urls import path
urlpatterns = [
path('', views.index, name='index'),
path('detail', views.detail, name='detail'),
path('resultat', views.form_data, name='resultat')
]
from django.shortcuts import render
from django.http import HttpResponse, HttpResponseRedirect
from appli.forms import Formulaire
from appli.models import Exercice
from django.db.models import Q
# Create your views here.
def index(request):
context = {}
context['form'] = Formulaire()
return render( request, 'appli/index.html', context)
'''def form_data(request):
# if this is a POST request we need to process the form data
if request.method == 'POST':
# create a form instance and populate it with data from the request:
form = Formulaire(request.POST)
# check whether it's valid:
if form.is_valid():
# process the data in form.cleaned_data as required
# ...
# redirect to a new URL:
return HttpResponseRedirect('resultat.html')
# if a GET (or any other method) we'll create a blank form
else:
form = Formulaire()
return render(request, 'resultat.html', {'form': form})'''
def form_data(request):
return render(request, 'appli/resultat.html', {})
def detail(request):
exercices_deb=Exercice.objects.filter(Q(difficulte_exercice=1) | Q(difficulte_exercice=2))
exercices_int=Exercice.objects.filter(Q(difficulte_exercice=2) | Q(difficulte_exercice=3))
exercices_av=Exercice.objects.filter(Q(difficulte_exercice=3) | Q(difficulte_exercice=4))
context = {'exercices_deb':exercices_deb, 'exercices_int':exercices_int, 'exercices_av':exercices_av}
return render(request, 'appli/detail.html', context)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment