...
<h1 style="padding-top : 40px">{{ req.name }}</h1> <p class="infos">Soumis par moi le {{ req.fromd|date:"DATE_FORMAT" }}</p> <p><strong>ID :</strong> {{ req.id }}</p> <p><strong>Type de test :</strong> {{ req.typeOfTest }}</p> <p><strong>Nom :</strong> {{ req.name }}</p> <p><strong>Date de la requête :</strong> {{ req.fromd }}</p> <p><strong>Périmètre :</strong> {{ req.perimetre }}</p> <p><strong>Owner :</strong> {{ req.owner }}</p> <p><strong>Indice de compromission :</strong><br />{{ req.iocs|linebreaks }}</p> <p><strong>Message à l'utilisateur :</strong><br />{{ req.messageToUser|linebreaks }}</p> <p><strong>BAL Folder :</strong><br />{{ req.balFolder|linebreaks }}</p> <p><strong>Note :</strong><br />{{ req.note|linebreaks }}</p> <p><strong>Requête finie :</strong> {{ req.handled|linebreaks }}</p> <br /> <button onclick="location.href='{% url 'modification' req.id %}'" type="button">Editer la<br />requête</button>
...
def view_modif(request, id): # Construit le formulaire, soit avec les données postées, # soit vide si l'user accède pour la première fois à la page. req = get_object_or_404(Requete, id=id) form_m = RequeteFormEdit(instance=req) # Verif que les données envoyées sont valides. # Cette méthode renvoie False s'il n'y a pas de # donnée dans le form ou qu'il contient des erreurs. if form_m.is_valid(): # Ici, on traite les données du form form_m.typeOfTest = form_m.cleaned_data['typeOfTest'] form_m.name = form_m.cleaned_data['name'] form_m.tod = timezone.now form_m.perimetre = form_m.cleaned_data['perimetre'] form_m.owner = form_m.cleaned_data['owner'] form_m.iocs = form_m.cleaned_data['iocs'] form_m.messageToUser = form_m.cleaned_data['messageToUser'] form_m.balFolder = form_m.cleaned_data['balFolder'] # form_m.pj = form_m.cleaned_data['pj'] form_m.handler = form_m.cleaned_data['handler'] form_m.note = form_m.cleaned_data['handled'] form_m.handled = form_m.cleaned_data['note'] form_m.save()
# Nous pourrions ici envoyer l'e-mail grâce aux données # que nous venons de récupérer envoi = True redirect(home)
# Quoiqu'il arrive, on affiche la page du formulaire. return render(request, 'insertion/modification.html', locals())
from django.urls import pathfrom . import views
urlpatterns = [ path('', views.home, name='home'), path('liste', views.liste, name='liste'), path('requete/<int:id>', views.print_req, name='voir_req'), path('insertion/', views.view_insert, name='insertion'), path('edit/<int:id>', views.view_modif, name='modification'), path('connexion/', views.connexion, name='connexion'), path('deconnexion/', views.deconnexion, name='deconnexion')]
NoReverseMatch at /edit/1
Reverse for 'modification' with no arguments not found. 1 pattern(s) tried: ['edit/(?P<id>[0-9]+)$']
Request Method: GET Request URL: http://127.0.0.1:8000/edit/1 Django Version: 2.0 Exception Type: NoReverseMatch Exception Value: Reverse for 'modification' with no arguments not found. 1 pattern(s) tried: ['edit/(?P<id>[0-9]+)$']
Exception Location: /usr/lib/python3.7/site-packages/django/urls/resolvers.py in _reverse_with_prefix, line 632 Python Executable: /usr/bin/python
lire.html
...
<button onclick="location.href='{% url 'modification' req.id %}'" type="button">Editer la<br />requête</button>
...
urls.py
path('edit/<int:id>', views.view_modif, name='modification'),
error :
NoReverseMatch at /edit/1
Reverse for 'modification' with no arguments not found. 1 pattern(s) tried: ['edit/(?P<id>[0-9]+)$']
Request Method: GET Request URL: http://127.0.0.1:8000/edit/1 Django Version: 2.0 Exception Type: NoReverseMatch Exception Value: Reverse for 'modification' with no arguments not found. 1 pattern(s) tried: ['edit/(?P<id>[0-9]+)$']Exception Location: /usr/lib/python3.7/site-packages/django/urls/resolvers.py in _reverse_with_prefix, line 632 Python Executable: /usr/bin/python
Thanks James for your help.Indeed, I tought about that problem but I already managed to see an number on an other page, as well as using that ID to read information behind my informations (as you can see in the third line I gave on "lire.html"). A number is printed. How can I know that it is an int and not a string use in there ?
# Nous pourrions ici envoyer l'e-mail grâce aux données# que nous venons de récupérerenvoi = Trueredirect(home)
def home(request): """ Acceuil du site qui recense toutes nos requêtes pour le moment """ return render(request, 'insertion/accueil.html', locals())
return render(request, 'insertion/modification.html', locals())
The line with a problem is that one
return render(request, 'insertion/modification.html', locals())And I really can't figure it out why, according the fact that "locals()" contains my variable and even if I send directly my variable instead, I get the same !