#31964 closed Uncategorized (invalid)

NoReverseMatch at / Reverse for 'home-page' not found. 'home-page' is not a valid view function or pattern name.

Reported by: kukesh-yiddish Owned by: nobody
Component: Generic views Version: 3.1
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by Mariusz Felisiak)

The same problem.i am struggled with this for a day please guide me

project url.py:

from django.contrib import admin
from django.urls import path, include

urlpatterns = [
    path('admin/', admin.site.urls),
    path('accounts/', include('allauth.urls')),
    path('', include('E_shop.urls', namespace='E_shop')),

app url.py:

from django.urls import path
from . import views

app_name ='E_shop'

urlpatterns = [
    path('', views.HomeView.as_view(), name='home-page'),
    path('checkout/', views.check_out, name='check-out'),
    path('product/<slug>/', views.ItemDetailView.as_view(), name='product-page')


from django.shortcuts import render
from django.views.generic import ListView, DetailView
from .models import Item

class HomeView(ListView):
    model = Item
    template_name = 'home.html'

class ItemDetailView(DetailView):
    model = Item
    template_name = 'product.html'

def check_out(request):
    return render(request, 'checkout.html')


from django.db import models
from django.conf import settings
from django.shortcuts import reverse

    ('S', 'Shirt'),
    ('SW', 'Sport Wear'),
    ('OW', 'Outwear')
    ('P', 'blue'),
    ('S', 'yellow'),
    ('D', 'red')

class Item(models.Model):
    title = models.CharField(max_length=100)
    price = models.FloatField()
    category = models.CharField(choices=CATEGORY_CHOICES, max_length=2)
    label = models.CharField(choices=LABEL_CHOICES, max_length=1)
    slug = models.SlugField(unique=True)

    def __unicode__(self):
        return self.title

    class Meta:
        unique_together = ('title', 'slug')

    def __str__(self):
        return self.title

    def get_absolute_url(self):
        return reverse('E_shop:product-page', kwargs={'slug': self.slug})

class OrderItem(models.Model):
    item = models.ForeignKey(Item, on_delete=models.CASCADE)

class Order(models.Model):
    user = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE)
    items = models.ManyToManyField(OrderItem)
    start_date = models.DateTimeField(auto_now_add=True)
    ordered_date = models.DateTimeField()
    ordered = models.BooleanField(default=False)

    def __str__(self):
        return self.user.username

html code

<a class="nav-link waves-effect" href="{% url 'home-page'  %}">Home

Attachments (1)

urls.py (293 bytes) - added by kukesh-yiddish 21 months ago.

Download all attachments as: .zip

Change History (2)

Changed 21 months ago by kukesh-yiddish

Attachment: urls.py added

comment:1 Changed 21 months ago by Mariusz Felisiak

Description: modified (diff)
Resolution: invalid
Status: newclosed

You should use a namespaced URL, i.e. {% url 'E_shop:home-page' %}.

Please don't use Trac as a support channel. Closing per TicketClosingReasons/UseSupportChannels.

Note: See TracTickets for help on using tickets.
Back to Top