Skip to content

Instantly share code, notes, and snippets.

@khamidou
Forked from selimhamidou/index.html
Last active June 11, 2020 16:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save khamidou/240325ee4cae1513b0f78988b091f99c to your computer and use it in GitHub Desktop.
Save khamidou/240325ee4cae1513b0f78988b091f99c to your computer and use it in GitHub Desktop.
<form method = "POST" action="resultat.html"> {% csrf_token %}
<select name="entry_to_delete">
{% for product_name, product_id in history %}
<option value={{ product_id }}>{{ product_name }}</option>
{% endfor %}
</select>
<input type = "submit" value = "Submit">
</form>
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 'entry_to_delete' in request.POST:
# check whether there's a valid object and it's own by the right user.
# then delete it.
# if a GET (or any other method) we'll create a blank form
else:
form = Formulaire()
return render(request, 'resultat.html', {'form': form})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment