View Full Version : Django Set site index
nobody
May 29th, 2008, 03:41 PM
So for the most part in Django I have no problem setting an app index. But what about the actual project, how do I set an index for that?
I'm probably not explaining myself well but if you go to www.thisandco.com I get a routing error, I'm just curious how I would set it up to server a template.
andr.in
May 29th, 2008, 04:17 PM
I'm not sure what you mean exactly but to get rid of the error you should have a regexp matching a blank url in you urls.py.
e.g.
(r'^$', 'somesite.someapp.views.index') #or whatever view you'd like to serve as root
nobody
May 29th, 2008, 05:55 PM
Gotcha, so I have to have an app specifically for an index page?
The way I see it I have:
project/app
So this translates to
site.com/app
I can set an index to site.com/app with the view like you posted, but what about just setting the index for site.com?
andr.in
May 30th, 2008, 08:37 AM
hmm I never questioned the methods I've been using, but I'm pretty sure you need to have an app to serve content. So the index content for the page has to come from some kind of app.
So basically I think you need to have an urls.py in your project folder where you include other urls.py-s (from different app folders) and you just need to route the index page to some view in some app separately.
Not 100% sure here but that's how I did it, which was a while ago...
nobody
May 30th, 2008, 02:42 PM
Yeah that sounds right. Hmmm. This stuff sure is confusing.
andr.in
May 31st, 2008, 09:14 AM
Not really once you get the hang of it. Django is still the best framework I've ever used, and without a doubt it has the best uri routing system I've come across.
But yeah this is coming from a guy who's never touched ruby on rails, but django sure beats the hell out of all the php frameworks that follow the MVC pattern if you ask me.
nobody
June 1st, 2008, 10:40 PM
Well then I suppose i won't give up.
Appreciate it, man =)
Jeff Wheeler
June 1st, 2008, 11:16 PM
You don't need to create a separate app for the index. I find it usually feeds on content primarily from one section (e.g. blog), so it makes sense to have it be a generic view with a relevant queryset.
I tend to often just have a direct_to_template, though, because I don't need anything complicated. I then just have a index.html template that it uses.
You could also, of course, write a view outside of any app and just use that in your urls.py file. Create a file views.py (or whatever you want to call it) in the root of your project and write your view there; it'll work just fine. :)
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.