用一行代码将您的动态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.xml
和robots.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 许可证 发布。
支持
另请参阅
-
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 的哈希值
算法 | 哈希摘要 | |
---|---|---|
SHA256 | 3d1aaab5948aa85c68c7cf982e850e22c23590ea06b4938c19a85e5772c5d14a |
|
MD5 | dc71ca4bc706196992f099d689a4b3bc |
|
BLAKE2b-256 | 170c92e07ae69886e8a7d87358db35f1cf2afee16b21208ee1ae615a213ae5b5 |
django_freeze-0.11.1-py3-none-any.whl 的哈希值
算法 | 哈希摘要 | |
---|---|---|
SHA256 | b74180248541731ad3c4a74dea76aa7d6b7b9783c9a1d6f879ea2acc6786b1ba |
|
MD5 | 86ea01a31643748de213c1a0c4c5d342 |
|
BLAKE2b-256 | 2a6e77af2ad67a55e484989c7de79b491fc62a78a9ad0cc7666e0a35f91821ac |