Hi All:
I've written myself an ultra-simple CMS as a Django learning exercise.
It consists of a couple of simple models and a single template to serve
up articles which have previously been posted into the database from the
admin interface.
Everything seems to work okay, but I think my implementation could be
better. I have a single view function which at present looks like this:
-----begin-----
def servePage(request):
if request.path[1:] == '':
thisPage = Page.objects.get(name = unicode('home'))
else:
thisPage = Page.objects.get(name = unicode(request.path[1:]))
sidebar_list = Page.objects.filter(category = thisPage.category)
article_list = Article.objects.filter(page =
thisPage.id).order_by('-amendedon')
return render_to_response('base.html', locals())
------end------
Firstly, I suspect that my use of request.path[:1] to get the URL being
accessed is not the accepted Django way. Is there a better method?
Secondly, even with the generic view that I'm using, I still need to
have multiple entries in my urls.py file in order to make pages work, i.e:
urlpatterns = patterns('',
(r'^admin/(.*)', admin.site.root),
('^$', servePage),
(r'^home$', servePage),
(r'^about$', servePage),
(r'^family$', servePage),
(r'^aviation$', servePage),
(r'^linux$', servePage),
(r'^windows$', servePage),
(r'^coding$', servePage),
(r'^photo$', servePage),
(r'^gallery$', servePage),
(r'^ppl-diary$', servePage),
)
Is there a way to replace this with a catch all pattern which does not
break other things? I've tried patterns such as r'^' and this simply
leads to my static content being skipped, so I see the pages, but with
no stylesheet applied and all images missing.
I'm seeing a tantalizing clue from the 404 page that gets generated when
I have DEBUG = True in my settings file. When Django tells me what URL
patterns it tried, the very last one is "^static/(?P<path>.*)$" - I
suspect that if I knew how to incorporate that into my urls.py ahead of
my 'catchall' pattern, I'd be good to go...
I've Googled for terms like 'django generic view' and 'django multiple
url single view' but I can't find anything useful. I think that at this
level, my setup probably doesn;t matter, but if it does I'm using Django
1.2 on both Windows XP and Linux, with Python 2.7 and 2.6 respectively,
depending upon which machine I have my USB stick plugged into at the time.
--
Regards
Phil Edwards | PGP/GnuPG Key Id
Brighton, UK | 0xDEF32500
--
You received this message because you are subscribed to the Google Groups "Django
users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at
http://groups.google.com/group/django-users?hl=en.