Django- NoReverseMatch. Reverse for '' with arguments '(2,)' and keyword arguments '{}' not found. 0 pattern(s) tried: []

deathstroke

I'm trying to pass a value from my template file to a function in the views.py file in Django.

My project structure is as follows-

myproject/
    manage.py
    myproject/
        __init__.py
        urls.py
        wsgi.py
        views.py
        settings.py
    orders/
        __init__.py
        models.py
        views.py
        urls.py
        tests.py
    restaurant/
        __init__.py
        models.py
        views.py
        urls.py
        tests.py

     requirements.txt

Here's my templates/menu.html file -

...
...    
{% for id,image,menu in imageList %}
    <div style = "display:inline-block">
        <img src="{{ MEDIA_URL }}{{ image }}">
        <p>{{ menu }}</p>
        <a href="{% url 'addCart' id %}">+</a>
        <a href="">-</a>
    </div>
{% endfor %}
...
...

The orders/urls.py is -

....
from orders.views import add_to_cart

urlpatterns = patterns('',
    url(r'^add/(?P<product_id>\d+)$', add_to_cart, name ='addCart'),
)

And the root urls.py is -

from orders.views import *

urlpatterns = patterns('',
    url(r'^$', menu),
    url(r'^admin/', include(admin.site.urls)),
    url(r'^orders/', include('orders.urls', namespace = "addCart")),
)

And finally, the orders/views.py is as follows-

def add_to_cart(request, product_id):
    product = Inventory.objects.get(id=product_id)
    ....

On executing this, the homepage, which calls the menu.html page gives the error-

Reverse for 'addCart' with arguments '(2,)' and keyword arguments '{}' not found. 0 pattern(s) tried: []

It says that the error is during the template rendering, specifically at the line -

<a href="{% url 'addCart' id %}">+</a>

I've tried a lot of different solutions, but nothing seems to work. I've tried using orders:addCart in the tag, too. BUt it doesn't work. Is it because of the views that I'm importing from the orders app is of the wrong format? Thank you.

knbk

Your url lives in the namespace 'addCart', so you'll have to specify that when reversing the url:

{% url 'addCart:addCart' id %}

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

NoReverseMatch at / Reverse for 'password_change_done' with arguments '()' and keyword arguments '{}' not found. 0 pattern(s) tried: []

From Dev

NoReverseMatch at / Reverse for 'password_change_done' with arguments '()' and keyword arguments '{}' not found. 0 pattern(s) tried: []

From Dev

Django NoReverseMatch error Reverse for 'detail' with arguments '('',)' and keyword arguments '{}' not found

From Dev

Reverse for '' with arguments '()' and keyword arguments '{}' not found. 0 pattern(s) tried: []

From Dev

Django: URL Reverse for '/job/job_view/' with arguments '()' and keyword arguments not found. 0 pattern(s) tried: []

From Dev

NoReverseMatch at /admin/ Reverse for 'logout' with arguments '()' and keyword arguments '{}' not found

From Dev

Django: Reverse for 'detail' with arguments '('',)' and keyword arguments '{}' not found

From Dev

Django Reverse for '' with arguments '('',)' and keyword arguments '{}' not found Error

From Dev

Django: Reverse for 'detail' with arguments '('',)' and keyword arguments '{}' not found

From Dev

Reverse for 'index' with arguments '()' and keyword arguments '{}' not found. 0 pattern(s) tried: []

From Dev

Reverse for 'quote-new' with arguments '()' and keyword arguments '{}' not found. 0 pattern(s) tried: []

From Dev

Reverse for 'userlist' with arguments '()' and keyword arguments '{}' not found. 0 pattern(s) tried: []

From Dev

Reverse for ' write' with arguments '()' and keyword arguments '{}' not found. 0 pattern(s) tried: []

From Dev

Reverse for 'home' with arguments '()' and keyword arguments '{}' not found. 0 pattern(s) tried: []

From Dev

Reverse for 'index' with arguments '()' and keyword arguments '{}' not found. 0 pattern(s) tried: []

From Dev

Reverse for 'quote-new' with arguments '()' and keyword arguments '{}' not found. 0 pattern(s) tried: []

From Dev

Reverse for 'userlist' with arguments '()' and keyword arguments '{}' not found. 0 pattern(s) tried: []

From Dev

DRF - Reverse for 'widget-detail' with arguments '()' and keyword arguments '{u'pk': ''}' not found. 0 pattern(s) tried: []

From Dev

Reverse for 'post/profile/' with arguments '()' and keyword arguments '{'user': 1}' not found. 0 pattern(s) tried: []

From Dev

Reverse for 'detail.view' with arguments '()' and keyword arguments '{}' not found. 0 pattern(s) tried: []

From Dev

reverse for ' with arguments '()' and keyword arguments not found. 1 pattern(s) tried:

From Dev

NoReverseMatch at /answer/ Reverse for 'detail' with keyword arguments '{'pk': 1}' not found. 1 pattern(s) tried: ['answer/$(?P<pk>\\d+)/$']

From Dev

Reverse for '' with arguments and keyword arguments '' not found

From Dev

Reverse for 'jobpost_detail' with arguments '()' and keyword arguments '{'slug': u'67itut'}' not found. 0 pattern(s) tried: []

From Dev

Reverse for 'post_detail' with arguments '('',)' and keyword arguments '{}' not found. 1 pattern(s) tried: ['posts/(?P[0-9]+)/$']

From Dev

Django: Reverse for 'delete' with arguments '(49,)' and keyword arguments '{}' not found. 1 pattern(s) tried: ['tidbit/delete_tidbit/']

From Dev

Reverse for 'home' with arguments '()' and keyword arguments '{}' not found. 0 pattern(s)

From Dev

django-allauth returns error "Reverse ... with arguments '()' and keyword arguments '{}' not found"

From Dev

NoReverseMatch at / Reverse for 'singlepropa' with arguments '('mens-shirt-1',)' not found. 1 pattern(s) tried

Related Related

  1. 1

    NoReverseMatch at / Reverse for 'password_change_done' with arguments '()' and keyword arguments '{}' not found. 0 pattern(s) tried: []

  2. 2

    NoReverseMatch at / Reverse for 'password_change_done' with arguments '()' and keyword arguments '{}' not found. 0 pattern(s) tried: []

  3. 3

    Django NoReverseMatch error Reverse for 'detail' with arguments '('',)' and keyword arguments '{}' not found

  4. 4

    Reverse for '' with arguments '()' and keyword arguments '{}' not found. 0 pattern(s) tried: []

  5. 5

    Django: URL Reverse for '/job/job_view/' with arguments '()' and keyword arguments not found. 0 pattern(s) tried: []

  6. 6

    NoReverseMatch at /admin/ Reverse for 'logout' with arguments '()' and keyword arguments '{}' not found

  7. 7

    Django: Reverse for 'detail' with arguments '('',)' and keyword arguments '{}' not found

  8. 8

    Django Reverse for '' with arguments '('',)' and keyword arguments '{}' not found Error

  9. 9

    Django: Reverse for 'detail' with arguments '('',)' and keyword arguments '{}' not found

  10. 10

    Reverse for 'index' with arguments '()' and keyword arguments '{}' not found. 0 pattern(s) tried: []

  11. 11

    Reverse for 'quote-new' with arguments '()' and keyword arguments '{}' not found. 0 pattern(s) tried: []

  12. 12

    Reverse for 'userlist' with arguments '()' and keyword arguments '{}' not found. 0 pattern(s) tried: []

  13. 13

    Reverse for ' write' with arguments '()' and keyword arguments '{}' not found. 0 pattern(s) tried: []

  14. 14

    Reverse for 'home' with arguments '()' and keyword arguments '{}' not found. 0 pattern(s) tried: []

  15. 15

    Reverse for 'index' with arguments '()' and keyword arguments '{}' not found. 0 pattern(s) tried: []

  16. 16

    Reverse for 'quote-new' with arguments '()' and keyword arguments '{}' not found. 0 pattern(s) tried: []

  17. 17

    Reverse for 'userlist' with arguments '()' and keyword arguments '{}' not found. 0 pattern(s) tried: []

  18. 18

    DRF - Reverse for 'widget-detail' with arguments '()' and keyword arguments '{u'pk': ''}' not found. 0 pattern(s) tried: []

  19. 19

    Reverse for 'post/profile/' with arguments '()' and keyword arguments '{'user': 1}' not found. 0 pattern(s) tried: []

  20. 20

    Reverse for 'detail.view' with arguments '()' and keyword arguments '{}' not found. 0 pattern(s) tried: []

  21. 21

    reverse for ' with arguments '()' and keyword arguments not found. 1 pattern(s) tried:

  22. 22

    NoReverseMatch at /answer/ Reverse for 'detail' with keyword arguments '{'pk': 1}' not found. 1 pattern(s) tried: ['answer/$(?P<pk>\\d+)/$']

  23. 23

    Reverse for '' with arguments and keyword arguments '' not found

  24. 24

    Reverse for 'jobpost_detail' with arguments '()' and keyword arguments '{'slug': u'67itut'}' not found. 0 pattern(s) tried: []

  25. 25

    Reverse for 'post_detail' with arguments '('',)' and keyword arguments '{}' not found. 1 pattern(s) tried: ['posts/(?P[0-9]+)/$']

  26. 26

    Django: Reverse for 'delete' with arguments '(49,)' and keyword arguments '{}' not found. 1 pattern(s) tried: ['tidbit/delete_tidbit/']

  27. 27

    Reverse for 'home' with arguments '()' and keyword arguments '{}' not found. 0 pattern(s)

  28. 28

    django-allauth returns error "Reverse ... with arguments '()' and keyword arguments '{}' not found"

  29. 29

    NoReverseMatch at / Reverse for 'singlepropa' with arguments '('mens-shirt-1',)' not found. 1 pattern(s) tried

HotTag

Archive