NoReverseMatch at /someurlname/ - Reverse for 'htmlname' with arguments '('1',)' not found. 1 pattern(s) tried: ['somehtmlname/$']

49 views
Skip to first unread message

Ivan Martić

unread,
Jan 24, 2019, 7:28:03 AM1/24/19
to Django users
Hi all,

i am having issue with url tag, every time i put url tag like --{% url 'productsgrouping' item.id%}-- i get no reverse error.
Can you help me figure it out on what am i doing wrong?

view:
def productsgrouping_view(request):
queryset = MaterialGroup.objects.all()
context = {"list" : queryset}
return render(request, 'qif/productsgrouping/productsgroup.html', context)

def productsgrouping_update_view(request, url_id):
product_lista = MaterialGroup.objects.get(id=url_id)
product_url_id = ProductgroupinputForm(request.POST or None, instance=product_lista)
context1 = {'product_url_id': product_url_id, 'product_lista': product_lista}

if product_url_id.is_valid():
product_url_id.save()

return render(request, 'productsgroup-update.html', context1)

url:
urlpatterns = [
    path('', views.productsgrouping_view, name='productsgrouping'),
    path('update/<int:url_id>/', views.productsgrouping_update_view, name='update_productsgrouping'),
    path('new/', views.creategroup_view, name='create_group'),
]

html:
{% extends 'base.html' %}
{% block content %}
<ul >
{% for item in list %}
<h1>
<a href="{% url 'productsgrouping' item.id%}"></a>
{{ item }} - {{item.id}} 
</h1>
{% endfor %}
{% endblock %}

traceback.txt

Andréas Kühne

unread,
Jan 24, 2019, 7:43:45 AM1/24/19
to django...@googlegroups.com
Hi, 

The reason you are getting this is that you are adding an argument to the productsgrouping url - which doesn't take any arguments. 

In your code you have: 
<a href="{% url 'productsgrouping' item.id%}"></a>
(Which by the way isn't correct either, I think you mean: <a href="{% url 'productsgrouping' item.id%}">{{ item }} - {{item.id}} </a>)

If you look at the url for the producsgrouping view, you have:
path('', views.productsgrouping_view, name='productsgrouping'),

Which doesn't take any arguments, when you then add an argument django can't find the right URL.

You may mean: 
<a href="{% url 'update_productsgrouping' item.id%}">{{ item }} - {{item.id}} </a>
?

Regards,

Andréas


--
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...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/ca1ef95d-166a-40ef-91bc-16f2d704f2ee%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Ivan Martić

unread,
Jan 24, 2019, 7:54:20 AM1/24/19
to django...@googlegroups.com
Hi  Andréas,
sorry for misspeling in codes. All is working ok except when i try to put url tag for 'update_productsgrouping'. 
I need to update group with new products but It does not argument for group id.
What do you think i am doing wrong...?

Ivan Martić

unread,
Jan 29, 2019, 4:20:38 AM1/29/19
to django...@googlegroups.com
not sure what to say

Nebojsa Hajdukovic

unread,
Jan 29, 2019, 5:35:10 AM1/29/19
to django...@googlegroups.com
A što ne uradiš update preko class based view daleko je lakše?

Ako hoćeš preko funkcije ja radim sa get_object_or_404, ovako:
def productsgrouping_update_view(request, url_id):
product_lista = get_object_or_404(MaterialGroup, pk=url_id)


Ivan Martić

unread,
Jan 29, 2019, 6:00:45 AM1/29/19
to django...@googlegroups.com
Bok Nebojša,

mislim da je stvar u HTML možda prije, jer mi je ranije sve radilo..u jednom trenu je puknula veza. Neznam točno kada.
Znači, da odem na url productsgrouping prikaze sve grupe, kad kliknem na grupu (dodam joj a=href) no reverse mathc, ako maknem atribute u url dobijem #, a ako ručno upišem productsgrouping/update/1 onda prikaze i nastavi sve kako treba.
Znaci samo nemogu povezati ta dva linka....pogledaj htmlove u privitku

hvala ti za pomoć


html-productsgroup-update.txt
view.txt
html-productsgroup.txt

Nebojsa Hajdukovic

unread,
Jan 29, 2019, 6:16:48 AM1/29/19
to django...@googlegroups.com
neće raditi ali ne zbog html već zbog greške u views
probaj ovako 
def productsgrouping_update_view(request, url_id):
	assigned = get_object_or_404(Material, pk=url_id)

naravno prvo moraš da importuješ get object or 404:
from django.shortcuts import get_object_or_404

Ivan Martić

unread,
Jan 29, 2019, 7:52:23 AM1/29/19
to django...@googlegroups.com
napravio sam točno kako si rekao i dalje nece, isti error ...vec danima se mucim sa ovime..nešto drugo je posrijedi.





1.txt

Nebojsa Hajdukovic

unread,
Jan 29, 2019, 7:56:51 AM1/29/19
to django...@googlegroups.com
To je greška zato što ne može da nađe url_id ajd ako ne uspeš pogledaću večeras detaljno šta si radio pa da vidim gde je greška

Ivan Martić

unread,
Jan 29, 2019, 7:58:52 AM1/29/19
to django...@googlegroups.com
ok, pokušat ću. ak neuspijem posaljem ti sta god ti treba da pokusas sam rekreirati...ovo je zaista zeznuto

Ivan Martić

unread,
Jan 30, 2019, 4:56:34 AM1/30/19
to django...@googlegroups.com
Bok Nebojša, jel možeš uletit i pogledati molim te što radim krivo.

Znači, imam 2 aplikacije, prva abc radi a druga product groups ne radi..
Sve je kopirano u 2 privitka.

Da li imaš vremena pogledati pliz?
Šta god napravim, No reverse mi se javlja....... 
abc.txt
app2.txt

Ivan Martić

unread,
Feb 1, 2019, 3:27:28 AM2/1/19
to django...@googlegroups.com
Hi guys, any help on this matter? i still have noreverse issue. There is something wrong with my url nameing

Ivan Martić

unread,
Feb 1, 2019, 3:37:12 AM2/1/19
to django...@googlegroups.com
i think i found the issue, problem was in the html url tag..
i should look like this
href="{ url 'update_group' list_all.url_id }">

not like this
href="{ url 'update_group' item.id }">

thank you all
Reply all
Reply to author
Forward
0 new messages