#31964: NoReverseMatch at / Reverse for 'home-page' not found. 'home-page' is 
not a
valid view function or pattern name.
--------------------------------+--------------------------------------
     Reporter:  kukesh-yiddish  |                    Owner:  nobody
         Type:  Uncategorized   |                   Status:  closed
    Component:  Generic views   |                  Version:  3.1
     Severity:  Normal          |               Resolution:  invalid
     Keywords:                  |             Triage Stage:  Unreviewed
    Has patch:  0               |      Needs documentation:  0
  Needs tests:  0               |  Patch needs improvement:  0
Easy pickings:  0               |                    UI/UX:  0
--------------------------------+--------------------------------------
Changes (by felixxm):

 * status:  new => closed
 * resolution:   => invalid


Old description:

> 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

New description:

 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
 }}}

--

Comment:

 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.

-- 
Ticket URL: <https://code.djangoproject.com/ticket/31964#comment:1>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/072.02c40aed3500c80c3bc7afb55896930c%40djangoproject.com.

Reply via email to