<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    Sealyu

    --- 博客已遷移至: http://www.sealyu.com/blog

      BlogJava :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理 ::
      618 隨筆 :: 87 文章 :: 225 評論 :: 0 Trackbacks

    The flatpages app

    Django comes with an optional “flatpages” application. It lets you store simple “flat” HTML content in a database and handles the management for you via Django’s admin interface and a Python API.

    A flatpage is a simple object with a URL, title and content. Use it for one-off, special-case pages, such as “About” or “Privacy Policy” pages, that you want to store in a database but for which you don’t want to develop a custom Django application.

    A flatpage can use a custom template or a default, systemwide flatpage template. It can be associated with one, or multiple, sites.

    New in Django 1.0: Please, see the release notes

    The content field may optionally be left blank if you prefer to put your content in a custom template.

    Here are some examples of flatpages on Django-powered sites:

    Installation

    To install the flatpages app, follow these steps:

    1. Install the sites framework by adding 'django.contrib.sites' to your INSTALLED_APPS setting, if it’s not already in there.

      Also make sure you’ve correctly set SITE_ID to the ID of the site the settings file represents. This will usually be 1 (i.e. SITE_ID = 1, but if you’re not using the sites framework to manage multiple sites, it could be the ID of a different site.

    2. Add 'django.contrib.flatpages' to your INSTALLED_APPS setting.

    3. Add 'django.contrib.flatpages.middleware.FlatpageFallbackMiddleware' to your MIDDLEWARE_CLASSES setting.

    4. Run the command manage.py syncdb.

    How it works

    manage.py syncdb creates two tables in your database: django_flatpage and django_flatpage_sites. django_flatpage is a simple lookup table that simply maps a URL to a title and bunch of text content. django_flatpage_sites associates a flatpage with a site.

    The FlatpageFallbackMiddleware does all of the work. Each time any Django application raises a 404 error, this middleware checks the flatpages database for the requested URL as a last resort. Specifically, it checks for a flatpage with the given URL with a site ID that corresponds to the SITE_ID setting.

    If it finds a match, it follows this algorithm:

    • If the flatpage has a custom template, it loads that template. Otherwise, it loads the template flatpages/default.html.
    • It passes that template a single context variable, flatpage, which is the flatpage object. It uses RequestContext in rendering the template.

    If it doesn’t find a match, the request continues to be processed as usual.

    The middleware only gets activated for 404s – not for 500s or responses of any other status code.

    Note that the order of MIDDLEWARE_CLASSES matters. Generally, you can put FlatpageFallbackMiddleware at the end of the list, because it’s a last resort.

    For more on middleware, read the middleware docs.

    Ensure that your 404 template works

    Note that the FlatpageFallbackMiddleware only steps in once another view has successfully produced a 404 response. If another view or middleware class attempts to produce a 404 but ends up raising an exception instead (such as a TemplateDoesNotExist exception if your site does not have an appropriate template to use for HTTP 404 responses), the response will become an HTTP 500 (“Internal Server Error”) and the FlatpageFallbackMiddleware will not attempt to serve a flat page.

    How to add, change and delete flatpages

    Via the admin interface

    If you’ve activated the automatic Django admin interface, you should see a “Flatpages” section on the admin index page. Edit flatpages as you edit any other object in the system.

    Via the Python API

    class models.FlatPage
    Flatpages are represented by a standard Django model, which lives in django/contrib/flatpages/models.py. You can access flatpage objects via the Django database API.

    Flatpage templates

    By default, flatpages are rendered via the template flatpages/default.html, but you can override that for a particular flatpage.

    Creating the flatpages/default.html template is your responsibility; in your template directory, just create a flatpages directory containing a file default.html.

    Flatpage templates are passed a single context variable, flatpage, which is the flatpage object.

    Here’s a sample flatpages/default.html template:

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"
    "http://www.w3.org/TR/REC-html40/loose.dtd">
    <html>
    <head>
    <title>{{ flatpage.title }}</title>
    </head>
    <body>
    {{ flatpage.content }}
    </body>
    </html>

    Since you're already entering raw HTML into the admin page for a flatpage, both flatpage.title and flatpage.content are marked as not requiring automatic HTML escaping in the template.

    posted on 2009-07-28 20:28 seal 閱讀(372) 評論(0)  編輯  收藏 所屬分類: Python
    主站蜘蛛池模板: 免费又黄又爽又猛大片午夜 | 亚洲视频在线观看免费| 全亚洲最新黄色特级网站| 亚洲人成未满十八禁网站| 羞羞网站免费观看| 精品国产免费一区二区| 亚洲无吗在线视频| 夜夜爽免费888视频| 亚洲 日韩经典 中文字幕| 国产成人免费爽爽爽视频| 亚洲熟妇成人精品一区| 黄a大片av永久免费| 无码一区二区三区亚洲人妻| 日本午夜免费福利视频| 亚洲av无码国产精品夜色午夜| 亚洲日本成本人观看| 麻豆国产VA免费精品高清在线| 亚洲av无码成人影院一区| 在线观看91精品国产不卡免费| 国产成人亚洲午夜电影| 99久久人妻精品免费一区| 久久亚洲日韩精品一区二区三区 | 日日躁狠狠躁狠狠爱免费视频| 亚洲视频在线精品| 久9久9精品免费观看| 国产成人精品亚洲日本在线| 黄a大片av永久免费| 久久嫩草影院免费看夜色| 亚洲AV第一页国产精品| 日日摸夜夜添夜夜免费视频| 亚洲中文字幕无码久久综合网| 亚洲jizzjizz少妇| 国产啪精品视频网免费| 亚洲JLZZJLZZ少妇| 亚洲国产成人高清在线观看| 日韩精品视频在线观看免费| 国产aⅴ无码专区亚洲av| 最近高清国语中文在线观看免费| 鲁啊鲁在线视频免费播放| 亚洲四虎永久在线播放| 日韩高清在线免费观看|