Wednesday, August 28, 2019

Re: Reverse for 'modification' with no arguments not found issue

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 ?

Le jeudi 22 août 2019 18:27:48 UTC+2, Ali IMRANE a écrit :
Hello everyone,

I know I may ask this question for another time for some of you but after an hour of research, I'm still stuck with this issue of "No Reverse Match".

Here is my problem :
  • First, I using forms to put information in my DB (tickets) ;
  • I want to be able to edit those informations (check if a ticket has been handled) ;
  • When I'm trying to call again my form to edit my information, even if I give a specific ID, no way to reach it.

lire.html
...
<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>
...

views.py
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())

urls.py
from django.urls import path
from . 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')
]

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


I'm in a hurry and hope I could have the help I need thanks to you.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/bf830ec3-b68d-4f56-9fb0-515586bbe900%40googlegroups.com.

No comments:

Post a Comment