0

I'm so new to django. Please a quick help will be much appreciated.

url(r'^shops/(?P<Newshop_id>[0-9]+)/$', views.shop_single, name='singleshop')

this path is given me page not found error.

models.py

from __future__ import unicode_literals
from django.db import models

class SliderTitle(models.Model):
    slider_title = models.CharField(max_length=20)
    def __str__(self):
        return self.slider_title

class Slider(models.Model):
    slider_type = models.OneToOneField(SliderTitle)
    slider = models.FileField(blank=True)
    def __str__(self):
        return str(self.slider_type)

class ShopCategories(models.Model):
    category = models.CharField(max_length=50, unique=True)
    def __str__(self):
        return self.category

class NewShop(models.Model):
    category = models.ForeignKey(ShopCategories)
    main_image = models.FileField()
    name = models.CharField(max_length=100, unique=True)
    tagline = models.CharField(max_length=50, default='Enter tagline here2')
    description = models.TextField(default='enter shop description')
    shop_image = models.FileField()
    def __str__(self):
        return  self.name

urls.py

urlpatterns = [
    url(r'^admin/', admin.site.urls),
    url(r'^$', views.homepage, name='homepage'),
    url(r'^about/', views.about, name='about'),
    url(r'^shops/(?P<Newshop_id>[0-9]+)/$', views.shop_single, name='singleshop')

views.py

def shop_single(request, Newshop_id):
    cat1 = NewShop.objects.filter(category_id=1)
    cat2 = NewShop.objects.filter(category_id=2)
    cat3 = NewShop.objects.filter(category_id=3)
    cat4 = NewShop.objects.filter(category_id=4)
    name1 = ShopCategories.objects.filter(id=1)
    name2 = ShopCategories.objects.filter(id=2)
    name3 = ShopCategories.objects.filter(id=3)
    name4 = ShopCategories.objects.filter(id=4)

    return render_to_response('shop_single.html', {'shop_name1': name1, 'shop_name2': name2, 'shop_name3': name3,
                                             'shop_name4': name4, 'Shop_cat1': cat1, 'Shop_cat2': cat2,
                                             'Shop_cat3': cat3,
                                             'Shop_cat4': cat4, })

my DB from phpmyadin

3
  • what is the stack trace you see ? Commented Feb 22, 2017 at 1:34
  • URLs containing a regex like (?P<Newshop_id>[0-9]+) are usually used to retreive an existing object record. The Newshop_id variable is apparently never used in your view, meaning you are not retrieving anything. What do you intend to happen in this view? Commented Feb 22, 2017 at 3:22
  • You haven't even said what URL you are actually going to. Commented Feb 22, 2017 at 7:25

1 Answer 1

1

I think you are never using newshop_id in your view.

So you need not to pass that newshop_id in your view and your url.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks alot, i had to just read the full documentation of URL again. I had it fixed. Learning a programming language requires lots of patience and persistence

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.