Reverse for 'modification' with no arguments not found issue

778 views
Skip to first unread message

Ali IMRANE

unread,
Aug 22, 2019, 12:27:48 PM8/22/19
to Django users
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.

James Schneider

unread,
Aug 22, 2019, 2:05:48 PM8/22/19
to django...@googlegroups.com


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



The error is saying you have no arguments to the {% url %} tag. Make sure that req.id is actually resolving to an integer value. 

Templates are fun when they mask missing values like that. You already have it displayed earlier in the template. Comment out the {% url %} tag and see if a number is displayed in your template.

-James

Ali IMRANE

unread,
Aug 28, 2019, 5:00:19 AM8/28/19
to Django users
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 ?

James Schneider

unread,
Aug 28, 2019, 9:55:52 PM8/28/19
to django...@googlegroups.com


On Wed, Aug 28, 2019, 2:00 AM Ali IMRANE <ali.im...@gmail.com> wrote:
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 ?

In the template it won't matter whether it is an int or a string, it gets implicitly converted to a string for the regex match anyway.



        # Nous pourrions ici envoyer l'e-mail grâce aux données
        # que nous venons de récupérer
        envoi = True
        redirect(home)


What is the home variable in the redirect statement above? It isn't defined in your view. I think that will need an extra argument. What line is the traceback actually complaining about?

-James

Ali IMRANE

unread,
Aug 29, 2019, 8:34:01 AM8/29/19
to Django users
My "home" variable is defined with a view :

def home(request):
    """ Acceuil du site qui recense toutes nos requêtes pour le moment """
    return render(request, 'insertion/accueil.html', locals())

Which redirect to my homepage.

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 !



Le jeudi 29 août 2019 03:55:52 UTC+2, James Schneider a écrit :

James Schneider

unread,
Aug 31, 2019, 1:01:11 PM8/31/19
to django...@googlegroups.com




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 !

There's probably a URL tag in that template that is missing a variable or has a typo in the variable reference. The error is complaining about a reverse call, not a render call. It might be in a different part of the traceback or error page. You need to look closer at the original error page, it probably cites something in the modification.html template, and you didn't post that one.

-James

Reply all
Reply to author
Forward
0 new messages