Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django - Website Home Page

Tags:

python

django

I've been having a look at Django and, from what I've seen, it's pretty darn fantastic. I'm a little confused, however, how I go about implementing a "home page" for my website? Would it be a separate app, or just a view within the project, or what?

like image 343
Peter Avatar asked Jun 09 '09 19:06

Peter


People also ask

Can you build a full website with Django?

Django is a fully featured Python web framework that can be used to build complex web applications.

Is Django good for websites?

Django is a great choice for just about any web development project. It's particularly good for social media sites or e-commerce sites that require a strong and secure foundation because the Django framework has built-in features that are great for protecting sensitive data, transactions and user authentication.


3 Answers

There's no real rule for this, But one thing I like to do is actually arrange for the index access to redirect to another spot. If you prefer, though, you can just give the index page a plain view.

That said, It's probably a good idea to keep all your code in an actual app, so that you can refactor it more easily, and so that it appears on the python path as a normal module. Putting views in the project rather than an app seems to cause more headaches than it solves.

like image 138
SingleNegationElimination Avatar answered Oct 30 '22 19:10

SingleNegationElimination


I just found my original approach (direct_to_template) is deprecated in Django 1.5

Instead, use a TemplateView to achieve the same result

from django.conf.urls import patterns, include, url
from django.views.generic import TemplateView

urlpatterns = patterns('',
    (r'^$', 
        TemplateView.as_view(template_name='index.html'),
        name='index'),
)

(For Django 1.4) You can setup a direct_to_template url within ./project/project/urls.py

from django.conf.urls import patterns, include, url
from django.views.generic.simple import direct_to_template

urlpatterns = patterns('',
    (r'^$', direct_to_template, { 'template': 'index.html'}),
    # add urls to apps here
)

For both, place the template (index.html) in your TEMPLATE_DIRS root. This is one approach to create a homepage without implementing an entire app. There are many ways to make this happen as others have noted.

like image 25
bnjmn Avatar answered Oct 30 '22 19:10

bnjmn


The easiest way is using Django's "Flatpages". See this link for more info: http://docs.djangoproject.com/en/dev/ref/contrib/flatpages/

like image 45
Anthony Lewis Avatar answered Oct 30 '22 18:10

Anthony Lewis