一个django应用程序,用于管理由使用标记语言编写的文章驱动的博客
django-rstblog的Python项目详细描述
django-rstblog是一个django应用程序,用于管理由所写文章驱动的博客 使用reStructuredText,或Markdown或HTML。
基本思想是采用hybrid发布模型, 介于静态站点(纯html)和动态站点(都在db中, 作为Wordpress)。
实际上,作者是在本地的个人电脑上写文章的,然后
- 他在文章的顶部加了一系列的行;它们用来 对其进行分类,指明使用的语言、标题和其他属性…
- 以及一行固定格式的文本,将属性与 文章内容。
最后,他调用网站的地址(url),允许他上传文章。 如果用户未登录到站点,则此地址要求输入用户和密码。
当文章上载到站点时,rstblog使用其属性 在数据库中分类。文章内容未加载 在数据库中;必要时,从网站上载的文件中恢复。
如果作者想修改文章的内容(或其属性), 他在电脑上编辑文件,然后再次上传。
为什么使用rstblog?
是什么原因导致我们做出这种设计选择?以下内容:
- 我们总是可以指望本地备份站点的所有内容;
- 我们可以在没有互联网连接的情况下工作,并且只有在 我们想上传;
- 该程序非常轻巧,在 有限的CPU容量,因为RAM和HDU空间很小(只要访问 我们没有这个问题:—); 我们不放弃DB允许的研究的灵活性和速度;
- 如果我们有几篇文章[1],那么可以使用支持库实现db python的(sqlite3),不使用大程序(在某种意义上 他们投入了大量资源)作为MySQL,或者PostgreSQL,…
功能
该项目目前实现的功能是:
- 条款索引,指明磋商次数 每一篇文章及其主要属性;
- 展示文章;
- 上传文章;
- 从上传到网站的文章文件开始,完成数据库的重建;
- 使用Django的管理界面管理数据库内容;
- 文章可能有翻译,可以有多种语言;
- 站点统计的指示;从文章的数量来看 装载,使用多少种语言,每种语言有多少文章 分类主题和语言。
cons
使用这种环境的缺点是什么?你一定有一个 精通python/django,收件人:
- 根据您的需要定制项目;
- 将其安装到生产服务器中。
a(不是这样)快速启动
激活虚拟环境后,加载所需的要求:
pip install django-rstblog
在project setting.py文件中:
1.1. Add ^{tt2}$ to your INSTALLED_APPS like this:
INSTALLED_APPS = [ ... 'django.contrib.sites', # django's sites framework 'fullurl', # django-fullurl ... 'rstblog', ]
1.2. check for presence of login parameters:
... LOGIN_REDIRECT_URL = '/' # It means home view LOGIN_URL = '/login/' ...
1.3. Add a RSTBLOG configuration section like this:
RSTBLOG = { 'ARTICLES_DIR': os.path.join(BASE_DIR, "contents", "articles"), 'START_CONTENT_SIGNAL': '.. hic sunt leones', # BEWARE: string on a single line, without other characters 'languages': { 'en': 'englis', # 1st position is default language (functioning on py 3.6+) 'it': 'italian', }, 'types': { 'article': 'article', # 1st position is default type (ok on py 3.6+) 'page': 'page', }, 'FIELDS': {'markup', 'image', 'atype', 'language', 'title', 'created', 'modified', 'slug', 'category', 'published', 'offer_home', 'summary', 'authors', 'translation_of', }, 'LIST_FIELDS': {'authors',}, 'DT_FIELDS': { 'created', 'modified', }, 'BOOL_FIELDS': { 'published', 'offer_home', }, 'HOME_ITEMS': 10, }
1.4 check for presence of SITE_ID:
... SITE_ID = 1 ...
在project urls.py文件中:
2.1. include the ^{tt2}$ URLconf:
from django.urls import include ... path('blog/', include('rstblog.urls', namespace='rstblog')),
2.2. check for presence of login url:
from django.contrib.auth import views as auth_views ... path('login/', auth_views.LoginView.as_view(), name='login'), path('logout/', auth_views.LogoutView, {'next_page': settings.LOGIN_REDIRECT_URL}, name='logout'), ...
关于您的项目模板:
3.1. it must have a base.html template with this blocks used from rstblog templates:
{% block title %} {% block meta %} {% block link %} {% block content %}
3.2. check for the presence of ^{tt6}$ used in login.
在项目目录(live manage.py所在的目录)中,创建 目录contents/articles
运行python manage.py migrate以创建rstblog模型。
启动开发服务器并访问http://127.0.0.1:8000/admin/ 创建至少一个值为uncategorized的Category来加载项目 (您需要启用管理应用程序)。
启动开发服务器并访问http://127.0.0.1:8000/blog/ 显示空的文章列表。
在PC上准备一篇文章,如下所示:
:markup: restructuredtext :title: article :language: en :slug: article :category: uncategorized .. hic sunt leones ========= Article ========= This is the article content. And this is a secod paragraph of the article.
访问http://127.0.0.1:8000/blog/load-article以加载上一篇文章。
现在,如果你再次访问http://127.0.0.1:8000/blog/你会得到一个列表具有 一篇文章,如果你点击标题,就会显示出来 (网址:http://127.0.0.1:8000/blog/show/article)
这项工作是根据 MIT License 执照。
参考文献
这个项目是hosted on GitHub 在这里你会发现完整的环境 需要开发django-rstblog应用程序。意思是:不仅是应用程序,而且 即使是一个最小的django项目。
完整的文件是 hosted on Read the Docs。
[1] | Not so few: with hundreds articles, everything reacts well. |