urls not maching

93 views
Skip to first unread message

ngangsia akumbo

unread,
Jul 12, 2014, 8:01:05 AM7/12/14
to django...@googlegroups.com
i have a problem with my urls it keeps breaking

here is my url
from django.conf.urls import patterns, include, url
from django.contrib import admin
admin.autodiscover()
#from blogs import views

urlpatterns = patterns('blogs.views',
    url(r'^admin/', include(admin.site.urls)),
    ## news updates

    url(r'^blogs/', include('blogs.urls')),
                      
    url(r'^blogs/$', 'news_list'),
    url(r'^blogs/(?P<blog_id>\d+)/$', 'news_detail'),  This second url is not executing which i cant understand why

  
)


when i type on the browser 127.0.0.1:8000/blogs it give me the links to the list of blogs title which i inputed in the admin area.

when i now click on the links for it to out put the blog content it breaks and keeps giving me this error.

Page not found (404)
Request Method:    GET
Request URL:    http://127.0.0.1:8000/blogs//
Using the URLconf defined in BP.urls, Django tried these URL patterns, in this order:
^admin/
^blogs/ ^blogs/$
^blogs/ ^blogs/(?P<blog_id>\d+)/$
^blogs/$
^blogs/(?P<blog_id>\d+)/$
The current URL, blogs//, didn't match any of these.
You're seeing this error because you have DEBUG = True in your Django settings file. Chang





here are the views for the two urls

def news_list(request):
    news= Post.objects.order_by('-pub_date')[:5]
    template = loader.get_template('index.html')
    context = RequestContext(request, {
        'news': news,
    })
    return HttpResponse(template.render(context))


def news_detail(request, blog_id):
    post = Post.objects.get(slug=blog_id)
    context = {'post', post}
    return render_to_response('news_details.html', context, context_instance=RequestContext(request))

   

Please i need some help

Lachlan Musicman

unread,
Jul 12, 2014, 2:00:33 PM7/12/14
to django...@googlegroups.com
show slug on the model? how is it defined?
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users...@googlegroups.com.
> To post to this group, send email to django...@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/a0bfa67f-4f67-4d37-b2e4-8d56424b27b5%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.



--
The idea is that a beautiful image is frameable. Everything you need
to see is there: It’s everything you want, and it’s very pleasing
because there’s no extra information that you don’t get to see.
Everything’s in a nice package for you. But sublime art is
unframeable: It’s an image or idea that implies that there’s a bigger
image or idea that you can’t see: You’re only getting to look at a
fraction of it, and in that way it’s both beautiful and scary, because
it’s reminding you that there’s more that you don’t have access to.
It’s now sort of left the piece itself and it’s become your own
invention, so it’s personal as well as being scary as well as being
beautiful, which is what I really like about art like that.
-----------------------------------------------------------------------------------------------------------
Adventure Time http://theholenearthecenteroftheworld.com/

Tom Evans

unread,
Jul 12, 2014, 5:01:47 PM7/12/14
to django...@googlegroups.com
On Sat, Jul 12, 2014 at 9:01 AM, ngangsia akumbo <ngan...@gmail.com> wrote:
> i have a problem with my urls it keeps breaking
>
> here is my url
> from django.conf.urls import patterns, include, url
> from django.contrib import admin
> admin.autodiscover()
> #from blogs import views
>
> urlpatterns = patterns('blogs.views',
> url(r'^admin/', include(admin.site.urls)),
> ## news updates
>
> url(r'^blogs/', include('blogs.urls')),

This line says "Anything that starts with "blogs/", refer to the
urlconf in "blogs.urls"

>
> url(r'^blogs/$', 'news_list'),
> url(r'^blogs/(?P<blog_id>\d+)/$', 'news_detail'), This second url is
> not executing which i cant understand why

These urls start with "blogs/", and are never found because the first
url listed has already taken any request starting with "blogs/".

Either remove the include() line, or move those url()s below it to "blogs.urls".

Cheers

Tom

ngangsia akumbo

unread,
Jul 13, 2014, 9:52:40 AM7/13/14
to django...@googlegroups.com, teva...@googlemail.com


Here is the similar probe

views File
# Create your views here.
from blog.models import Post
from django.shortcuts import render_to_response
from django.template import RequestContext

def news_index(request):
    posts = Post.objects.all().order_by('published_date')
    context = {'posts': posts}
    return render_to_response('index.html', context, context_instance=RequestContext(request))


def news_detail(request, blogslug):
    posts = Post.objects.get(slug=blogslug)
    context = {'posts': posts}
    return render_to_response('news_detail.html', context, context_instance=RequestContext(request))

Model File

from django.db import models

# Create your models here.

class Reporter(models.Model):
    name = models.CharField(max_length=60, blank=True)
    tell = models.IntegerField(blank=True, null=True)
    location = models.CharField(max_length=50, blank=True, null=True)
    address = models.TextField(max_length=250)
   

class Post(models.Model):
    title = models.CharField(max_length=100)
    slug = models.SlugField(unique=True)
    published_date = models.DateTimeField(auto_now_add=True)
    image = models.ImageField(upload_to='static/blog')
    content = models.TextField()
    repoter = models.ForeignKey(Reporter)


    def __unicode__(self):
        return self.title

PROJECT/URLS


from django.conf.urls import patterns, include, url

#enable the admin:

from django.contrib import admin
admin.autodiscover()

urlpatterns = patterns('',
                      
    url(r'^blog/', include('blog.urls')),
    url(r'^admin/', include(admin.site.urls)),
)


APP/URL
from django.conf.urls import patterns, url
from blog import views

urlpatterns = patterns('',
   
    url(r'^$', views.news_index, name='news_index'),

WHEN I TYPE 127.0.0.1:8000/blog it outputs the first url in this file as a series of links.
    url(r'^(?P<blogslug>\d+)/$', views.news_detail, name='news_detail'),
When i clik on the links this second url breaks down, giving me the error below

)


Page not found (404)

Request Method: GET
Request URL: http://127.0.0.1:8000/blog//

Using the URLconf defined in rango.urls, Django tried these URL patterns, in this order:

  1. ^blog/ ^$ [name='news_index']
  2. ^blog/ ^(?P<blogslug>\d+)/$ [name='news_detail']
  3. ^admin/

The current URL, blog//, didn't match any of these.

You're seeing this error because you have DEBUG = True in your Django settings file. Change that to False, and Django will display a standard 404 pa


Please i really need help here

Jonathan Querubina

unread,
Jul 13, 2014, 11:52:20 AM7/13/14
to django...@googlegroups.com, teva...@googlemail.com
It seems tha you are using blog// (two slashes) on the url. Try blog/

Sent from my iPhone
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.

ngangsia akumbo

unread,
Jul 13, 2014, 2:19:08 PM7/13/14
to django...@googlegroups.com, teva...@googlemail.com
no am not using two slashes, i just want my block links to output the content details but i keep having the error above
i need some help here

ngangsia akumbo

unread,
Jul 13, 2014, 4:34:45 PM7/13/14
to django...@googlegroups.com, teva...@googlemail.com
can someone help me with a url that will work?


Thomas Lockhart

unread,
Jul 13, 2014, 6:08:57 PM7/13/14
to django...@googlegroups.com
On 7/13/14 7:19 AM, ngangsia akumbo wrote:
no am not using two slashes, i just want my block links to output the content details but i keep having the error above
i need some help here
You are getting some help here. The details you have provided so far seem to indicate that you are providing a URL with two slashes. You will need to provide more details to clarify that this is not the case.

Try cut and pasting the actual URL from your client into your next email.

hth

                               - Tom


On Sunday, July 13, 2014 12:52:20 PM UTC+1, Jonathan Querubina wrote:
It seems tha you are using blog// (two slashes) on the url. Try blog/


--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.

ngangsia akumbo

unread,
Jul 14, 2014, 1:08:24 AM7/14/14
to django...@googlegroups.com

Those are actual urls , i am actually still developing this site, so i decided to start with a blog first

Daniel Roseman

unread,
Jul 14, 2014, 8:14:16 AM7/14/14
to django...@googlegroups.com
On Monday, 14 July 2014 02:08:24 UTC+1, ngangsia akumbo wrote:

Those are actual urls , i am actually still developing this site, so i decided to start with a blog first

You *have* to help us help you. Thomas specifically requested that you show *exactly* what URL you are requesting. You replied with a single line which did not provide this information - and you complain that no-one is helping you. We want to help you, but we cannot, because you refuse to provide sufficient information.
--
DR.

ngangsia akumbo

unread,
Jul 14, 2014, 12:50:43 PM7/14/14
to django...@googlegroups.com
Thanks guys i actually solved my problem using class based views

To be honest that was all the information i had , i did not hide any information.
Thanks Guys


Reply all
Reply to author
Forward
0 new messages