Django如何设置主页面 [英] Django how to set main page

查看:283
本文介绍了Django如何设置主页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想为我的应用程序设置主页面或索引页面。
i尝试在settings.py中添加MAIN_PAGE,然后创建返回main_page对象的main_page视图,但不起作用
此外,我尝试在urls.py中添加一个声明,如

i want to set a main page or an index page for my app. i tried adding MAIN_PAGE in settings.py and then creating a main_page view returning a main_page object, but it doesn't work Also, i tries to add in the urls.py a declaration like

(r'^$', index),

其中indexs应该是根目录中的index.html文件的名称(但显然不起作用)

where indexshould be the name of the index.html file on the root (but it obviously does not work)

什么是最好的在Django网站中设置主页的方法?

What is the best way to set a main page in a Django website?

谢谢!

推荐答案

如果要引用静态页面(没有经过任何动态处理),可以使用中的 direct_to_template 视图函数django.views.generic.simple 。在您的URL conf中:

If you want to refer to a static page (not have it go through any dynamic processing), you can use the direct_to_template view function from django.views.generic.simple. In your URL conf:

from django.views.generic.simple import direct_to_template
urlpatterns += patterns("",
    (r"^$", direct_to_template, {"template": "index.html"})
)

(假设 index.html 位于您的一个模板目录的根目录。)

(Assuming index.html is at the root of one of your template directories.)

这篇关于Django如何设置主页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆