0

Hi im new to coding and django and im trying to create a simple e-commerce website but when clicking a button to redirect to cart but it is not going through. this error comes up when i initiate the server.


     File "C:\Users\ASUS\AppData\Local\Programs\Python\Python38\lib\sre_parse.py", line 831, in _parse
        raise source.error(err.msg, len(name) + 1) from None
    re.error: redefinition of group name 'id' as group 2; was group 1 at position 25

here is the html code

            <!-- Product Pricing -->
            <div class="product-price">
              <span>{{i.product_price}}</span>
              <a href="/cart/{{i.id}}/{{customer.id}}" class="cart-btn">Add to cart</a>
              <p>{{customer.id}}</p>
              <a href="" class="cart-btn">go to cart</a>
            </div>
   

my views code


    def cart(request,cid,pid) :
        p_info=product_info.objects.get(id=pid)
        c_info=login_details.objects.get(id=cid)
        return render(request, 'customer side/cart.html')

my appurl code



    urlpatterns=[
        path('register',views.save_login_info),
        path('cart/<int:id>/<int:id>/',views.cart),
        path('login',views.logging_in,name='login'),
        path('list',views.product_catalogue),
        path('new',views.add_product),
        path('savingdata',views.addnew,name='saving'),
    
        enter code here
    
    ]

``

the error apppears to have something to do with the url part of the cart when i remove on of the integer id from cart/int(id)/int(id) the error disappears but i need both numbers.
i tried assigning values to the variables in my views code but nothing seems to fix the problem.
please help.

  • You're assigning the name id to both variables in your url. Duplicate of: https://stackoverflow.com/questions/36193786/django-multiple-pks-in-url – aphenine Jul 22 '20 at 22:03
  • Does this answer your question? [Django multiple pks in url](https://stackoverflow.com/questions/36193786/django-multiple-pks-in-url) – aphenine Jul 22 '20 at 22:04

1 Answers1

0

You're asking for two arguments called ID and once the redirect happens, the second ID overwrites the first one. Just change the second one to customer_id or something and that will clear up your issue.

  urlpatterns=[
        path('register',views.save_login_info),
        path('cart/<int:product_id>/<int:customer_id>/',views.cart),
        path('login',views.logging_in,name='login'),
        path('list',views.product_catalogue),
        path('new',views.add_product),
        path('savingdata',views.addnew,name='saving'),
    
    ]
Harben
  • 1,802
  • 1
  • 11
  • 16