urls prob

32 views
Skip to first unread message

ngangsia akumbo

unread,
Jul 18, 2014, 12:41:25 PM7/18/14
to django...@googlegroups.com
urls

from django.conf.urls import patterns, include, url
from django.contrib import admin
admin.autodiscover()

from blogs.views import PostListView
from blogs.views import PostDetailView

from events.views import EventListView
from events.views import EventDetailView

urlpatterns = patterns('',
    
    #url(r'^blogs/', include('blogs.urls')),
    url(r'^admin/', include(admin.site.urls)),
                       
    #news urls                  
    url(r'^news$', PostListView.as_view(), name='home'),
    url(r'^(?P<slug>[-_\w]+)/$', PostDetailView.as_view(), name='Post-detail'),
                       
    #events urls
    url(r'^$', EventListView.as_view(), name='event'),
    url(r'^(?P<slug>[-_\w]+)/event/$', EventDetailView.as_view(), name='Event-detail'),  For God sake this urls keeps breaking

)

any help please?

views
# Create your views here.
from django.views.generic.list import ListView
from django.views.generic.detail import DetailView
from django.utils import timezone

from events.models import Event


class EventListView(ListView):
    models = Event
    queryset = Event.objects.all()

    def get_context_data(self, **kwargs):
        context = super(EventListView, self).get_context_data(**kwargs)
        context['now'] = timezone.now()
        return context

class EventDetailView(DetailView):

    model = Event
    #queryset = Event.objects.all()

    def get_context_data(self, **kwargs):
        context = super(EventDetailView, self).get_context_data(**kwargs)
        context['now'] = timezone.now()
        return context
    

model

from django.db import models

# Create your models here.
class Event(models.Model):
    name = models.CharField(max_length=100, verbose_name="Name of Event", blank=True)
    slug = models.SlugField(unique=True)
    type_of = models.CharField(max_length=100, blank=True, verbose_name="Type Of Event")
    image1 = models.ImageField(upload_to='blogs/static/events', blank=True)
    entertainer = models.CharField(max_length=100, blank=True)
    description = models.TextField(verbose_name="Details about the event", blank=True)
    speakers = models.CharField(max_length=100, blank=True)
    pub_date = models.DateTimeField(auto_now_add=True)
    location = models.CharField(max_length=100, blank=True)


    def __unicode__(self):
        return self.name







ngangsia akumbo

unread,
Jul 18, 2014, 12:43:29 PM7/18/14
to django...@googlegroups.com
it gives me this error

Page not found (404)

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

No post found matching the query

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 page.



Sergiy Khohlov

unread,
Jul 18, 2014, 12:56:38 PM7/18/14
to django-users
try to use
url(r'^/event/$', EventDetailView.as_view(), name='Event-detail')


 and ofcourse turn off color

Many thanks,

Serge


+380 636150445
skype: skhohlov


--
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/f68ef88b-e1a5-4aef-b0b3-cb91730ba312%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

ngangsia akumbo

unread,
Jul 18, 2014, 1:54:16 PM7/18/14
to django...@googlegroups.com
It is still breaking

Sergiy Khohlov

unread,
Jul 18, 2014, 3:06:23 PM7/18/14
to django-users
Ok,
 I've used some code from tutorials :
1) add apl akumbo
python manage startapp akumbo

2) add your models
3) add urls:

from django.conf.urls import patterns, include, url
from django.contrib import admin
from akumbo.views import EventListView
from akumbo.views import EventDetailView


urlpatterns = patterns('',
   
    #url(r'^blogs/', include('blogs.urls')),
    url(r'^admin/', include(admin.site.urls)),
                      
    #news urls                 
                      
    #events urls
    url(r'^$', EventListView.as_view(), name='event'),
    url(r'^(?P<slug>[-_\w]+)/event/$', EventDetailView.as_view(), name='Event-detail'),

)

4.  Check sql


serg@debian:~/project/django/tutor/mysite$ python manage.py  sql akumbo                                                                           
BEGIN;                                                                                                                                                       
CREATE TABLE `akumbo_event` (                                                                                                                                
    `id` integer AUTO_INCREMENT NOT NULL PRIMARY KEY,                                                                                                        
    `name` varchar(100) NOT NULL,                                                                                                                            
    `slug` varchar(50) NOT NULL UNIQUE,                                                                                                                      
    `type_of` varchar(100) NOT NULL,
    `image1` varchar(100) NOT NULL,
    `entertainer` varchar(100) NOT NULL,
    `description` longtext NOT NULL,
    `speakers` varchar(100) NOT NULL,
    `pub_date` datetime NOT NULL,
    `location` varchar(100) NOT NULL
)
;

run syncdb

python manage.py  syncdb
Creating tables ...
Creating table akumbo_event
Installing custom SQL ...
Installing indexes ...
Installed 0 object(s) from 0 fixture(s)


create a simple  template
serg@debian:~/project/django/tutor/mysite$ mkdir templates
serg@debian:~/project/django/tutor/mysite$ mkdir templates/akumbo
serg@debian:~/project/django/tutor/mysite$ touch templates/akumbo/event_list.html
serg@debian:~/project/django/tutor/mysite$ python manage.py  runserver

  lunch  app
 visit page  no error
Also I've update setting.py for supporting your urls 




Many thanks,

Serge


+380 636150445
skype: skhohlov


ngangsia akumbo

unread,
Jul 18, 2014, 3:12:45 PM7/18/14
to django...@googlegroups.com
i dont get you well


monoBOT

unread,
Jul 18, 2014, 3:21:52 PM7/18/14
to django...@googlegroups.com
The url "env/" is not validatingbecause the re is expecting 

r'^(?P<slug>[-_\w]+)/event/$'

and not 

r'^/event/$'

you have to check your re skills XD



For more options, visit https://groups.google.com/d/optout.



--
monoBOT
Visite mi sitio(Visit my site): monobotsoft.es/blog/

ngangsia akumbo

unread,
Jul 18, 2014, 3:25:46 PM7/18/14
to django...@googlegroups.com
i will check again
thanks , let me check again

Tom Evans

unread,
Jul 18, 2014, 3:31:49 PM7/18/14
to django...@googlegroups.com
On Fri, Jul 18, 2014 at 2:54 PM, ngangsia akumbo <ngan...@gmail.com> wrote:
>
> It is still breaking
>

You should explain precisely what is still breaking. "Still breaking"
doesn't tells anyone who is helping you what is going wrong.

In earlier emails, you are going to the URL "/event/", but in your
urls.py you specify the url as having a slug before the "/event/".

So, "/foo/event/" would match, and would pass slug='foo' to your view function.

Your url has no slug and so doesn't match. The strings have to match
exactly the regular expression.

Cheers

Tom

ngangsia akumbo

unread,
Jul 18, 2014, 3:40:08 PM7/18/14
to django...@googlegroups.com, teva...@googlemail.com
This is what is happening

i have created an event and added it to my admin.
I have added a content with title event and one with title news


  url(r'^$', EventListView.as_view(), name='event'),

The url above will list the event with order_by date and title

 
  url(r'^(?P<slug>[-_\w]+)/event/$', EventDetailView.as_view(), name='Event-detail')

the second url is suppose to output the content of the event.
but when i click on the first listings of even it give me the error above with an extension of event

so i tried adding event to url to see if it could change but still the content is not outputed

ngangsia akumbo

unread,
Jul 18, 2014, 4:06:21 PM7/18/14
to django...@googlegroups.com, teva...@googlemail.com
I solved the problem

the error was coming from the views.py
the list views did not define the model

thanks for the support
Reply all
Reply to author
Forward
0 new messages