Django - Website Home Page

前端 未结 3 1582
甜味超标
甜味超标 2021-02-07 03:53

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 we

3条回答
  •  野的像风
    2021-02-07 04:30

    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.

提交回复
热议问题