跳转到主要内容

用一行代码将您的动态Django站点转换为静态站点。

项目描述

django-freeze

django-freeze 生成您的 Django 站点的静态版本。

只需运行 python manage.py generate_static_site :)

特性

  • 生成 Django 站点的静态版本,可选压缩 .zip 文件
  • 使用 urls (仅超级用户和工作人员) 生成/下载 静态网站
  • 遵循 sitemap.xml urls
  • 遵循每页中找到的 内部链接
  • 遵循 重定向
  • 报告 无效/损坏的 urls
  • 选择性 包含/排除 媒体和静态文件
  • 自定义 基本 url (如果静态网站将在与文档根不同的特定文件夹中运行,则非常有用)
  • 将 urls 转换为 相对 urls (如果静态网站将在离线或与文档根不同的未知文件夹中运行,则非常有用)
  • 防止本地目录索引

安装

  • 运行 pip install django-freeze
  • freeze 添加到 settings.INSTALLED_APPS
  • 启用 sites 框架(说明 在此
  • 重新启动您的应用程序服务器

配置(可选)

所有这些设置都是可选的,如果未在 settings.py 中定义,则将使用以下列出的默认值。

#the absolute path where to store the .zip and the html files
#default value is a folder named 'freeze' located as sibling of 'settings.MEDIA_ROOT'
FREEZE_ROOT = '/...'

#tells 'freeze' if the urls should be fetched using https instead of http protocol (only if FREEZE_SITE_URL is not defined)
FREEZE_USE_HTTPS = False

#the site-url to crawl, if not specified it will be autodetected using the sites app
FREEZE_SITE_URL = 'http://mydomain.com'

#the base-url for all links relative to root '/'
#useful if the generated static site will run in a specific folder which is not the document-root
FREEZE_BASE_URL = None

#if True 'freeze' will convert all absolute urls to relative urls
#useful if the generated static site will run locally (file://) or in an unknown folder which is not the document-root (only if FREEZE_BASE_URL is not defined)
FREEZE_RELATIVE_URLS = False

#if True 'freeze' will inject a script at the end of each page
#which will force hrefs like 'path/' to 'path/index.html' (only if the site is running under file://)
#useful if the generated static site will run locally (requires FREEZE_RELATIVE_URLS set to True) to prevent local directory index
FREEZE_LOCAL_URLS = False

#if True 'freeze' will fetch each url founded in sitemap.xml
FREEZE_FOLLOW_SITEMAP_URLS = True

#if True 'freeze' will follow and fetch recursively each link-url founded in each page
FREEZE_FOLLOW_HTML_URLS = True

#if true 'freeze' will send an email to managers containing the list of all invalid urls (404, 500, etc..)
FREEZE_REPORT_INVALID_URLS = False

#the invalid urls email report subject
FREEZE_REPORT_INVALID_URLS_SUBJECT = '[freeze] invalid urls'

#if True the generated site will contain also the MEDIA folder and ALL its content
FREEZE_INCLUDE_MEDIA = True
#elif the value is a list or tuple only the specified directories will be included
FREEZE_INCLUDE_MEDIA = ('cache', 'images', 'videos', )

#if True the generated site will contain also the STATIC folder and ALL its content
FREEZE_INCLUDE_STATIC = True
#elif the value is a list or tuple only the specified directories will be included
FREEZE_INCLUDE_STATIC = ('myapp1', 'myapp2', 'myapp3', )

#if True the generated site will be zipped, the *.zip file will be created in FREEZE_ROOT
FREEZE_ZIP_ALL = False

#the name of the zip file created
FREEZE_ZIP_NAME = 'freeze'

#The request headers to use during the get requests that scrape the site
#can be used to set Authentication headers, by default sets the user-agent
FREEZE_REQUEST_HEADERS = {'user-agent': 'django-freeze'}

如果您希望超级用户和工作人员能够使用 freeze urls,请将 freeze.urls 添加到 urls.py

urlpatterns = patterns('',
    ...
    url(r'^freeze/', include('freeze.urls')),
    ...
)

用法

终端

运行 python manage.py generate_static_site

URLs

超级用户和工作人员可以使用以下 urls 下载 包含生成的静态网站 .zip 或仅生成静态网站。

/freeze/download-static-site/

/freeze/generate-static-site/

(生成静态网站所需的时间取决于项目的大小)

待办事项

  • 编写测试
  • sitemap.xmlrobots.txt 添加到生成的静态网站

测试

# clone repository
git clone https://github.com/fabiocaccamo/django-extra-settings.git && cd django-extra-settings

# create virtualenv and activate it
python -m venv venv && . venv/bin/activate

# upgrade pip
python -m pip install --upgrade pip

# install requirements
pip install -r requirements.txt -r requirements-test.txt

# install pre-commit to run formatters and linters
pre-commit install --install-hooks

# run tests
tox
# or
python runtests.py
# or
python -m django test --settings "tests.settings"

许可协议

根据 MIT 许可证 发布。


支持

  • :star: 在 GitHub 上星标此项目
  • :octocat: 在 GitHub 上关注我
  • :blue_heart: 在 Twitter 上关注我
  • :moneybag: 在 Github 上赞助我

另请参阅

  • django-admin-interface - 由管理员本身可定制的默认管理界面。用模态替换弹出窗口。 🧙 ⚡

  • django-cache-cleaner - 使用管理面板或管理命令轻松清除整个缓存或单个缓存。 🧹✨

  • django-colorfield - 模型中的简单颜色字段,管理中有漂亮的颜色选择器。 🎨

  • django-extra-settings - 使用 django admin 仅通过配置和管理类型化额外设置。 ⚙️

  • django-maintenance-mode - 当维护模式开启时显示 503 错误页面。 🚧 🛠️

  • django-redirects - 完全控制的重定向。 ↪️

  • django-treenode - 可能是针对基于树的内容的最佳抽象模型/管理器。 🌳

  • python-benedict - 具有键列表/键路径支持、I/O 快捷方式(base64、csv、json、pickle、plist、查询字符串、toml、xml、yaml)和许多实用工具的 dict 子类。 📘

  • python-codicefiscale - 对意大利税号进行编码/解码 - Codifica/decodifica del Codice Fiscale. 🇮🇹 💳

  • python-fontbro - 友好的字体操作。 🧢

  • python-fsutil - 懒人文件系统工具。 🧟‍♂️

项目详情


下载文件

下载适用于您的平台文件。如果您不确定选择哪个,请了解更多关于安装包的信息。

源代码分发

django_freeze-0.11.1.tar.gz (15.0 kB 查看哈希值)

上传时间 源代码

构建分发

django_freeze-0.11.1-py3-none-any.whl (16.5 kB 查看哈希值)

上传时间 Python 3

由以下机构支持

AWS AWS 云计算和安全赞助商 Datadog Datadog 监控 Fastly Fastly CDN Google Google 下载分析 Microsoft Microsoft PSF 赞助商 Pingdom Pingdom 监控 Sentry Sentry 错误记录 StatusPage StatusPage 状态页面