D
D
darkglare2020-10-12 13:43:54
Django
darkglare, 2020-10-12 13:43:54

Reverse for 'A' with arguments '('B',)' not found?

Hello. I don't understand how to set the url to get to the product page.

urls.py

from django.conf.urls import include
from django.contrib import admin
admin.autodiscover()
from django.conf.urls.static import static
from django.contrib.staticfiles.urls import staticfiles_urlpatterns
from django.conf import settings

urlpatterns = [

url(r'^$', app.views.home, name='home'),
url(r'^cart/', include('cart.urls', namespace='cart')),
url(r '^goods/', include('app.urls', namespace='app')), this line should open the product page
...

if settings.DEBUG:
urlpatterns += static(settings.MEDIA_URL,
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
urlpatterns += staticfiles_urlpatterns()

urls.py is the application file app

from django.conf.urls import url
from . import views

app_name = 'app'

urlpatterns = [
url(r'^$', views.product_list, name='product_list'),
url(r'/', views.product_list,
name='product_list_by_category'
),
url(r '/', views.product_detail,
name='product_detail')
]

models.py

class Category(models.Model):
name = models.CharField(max_length=100, db_index=True)
slug = models.SlugField(max_length=100, unique=True)

class Meta:
verbose_name = 'Category'
verbose_name_plural = 'Categories'

def __str__(self):
return self.name

def get_absolute_url(self):
return reverse('app:product_list_by_category', args=[self.slug])


views.py

def product_list(request , category_slug=None):
category = None
categories = Category.objects.all()
products = Product.objects.filter(available=True)
if category_slug:
category = get_object_or_404(Category, slug=category_slug)
products = products.filter(category =category)
return render(request, 'app/product/list.html',
{
'category': category,
'categories': categories,
'products':products
})

def product_detail(request, id, slug):
product = get_object_or_404(Product, id=id, slug=slug, available=True)
return render(request, 'app/product/detail.html', {'product': product} ) - along this path is the file

Please, explain "on the fingers" how to fix it. I check the topic every half an hour :)

when I write a link like localhost:53331/goods , the

5f84321debde8485471424.jpeg

5f8432384ddac146481340.jpeg processors error crashes - this is the name of the category in the admin panel

5f84324dad689081836696.jpeg

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question