Opened 4 years ago
Closed 4 years ago
#31964 closed Uncategorized (invalid)
NoReverseMatch at / Reverse for 'home-page' not found. 'home-page' is not a valid view function or pattern name. — at Version 1
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 )
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') ]
views.py:
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')
model.py:
from django.db import models from django.conf import settings from django.shortcuts import reverse CATEGORY_CHOICES = ( ('S', 'Shirt'), ('SW', 'Sport Wear'), ('OW', 'Outwear') ) LABEL_CHOICES = ( ('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
Change History (2)
by , 4 years ago
comment:1 by , 4 years ago
Description: | modified (diff) |
---|---|
Resolution: | → invalid |
Status: | new → closed |
Note:
See TracTickets
for help on using tickets.
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.