Blog

Viewing posts from April, 2019

Mezz 安装与配置

最近在迁移Linode主机时丢失了Movable Type的数据库备份,无法完全恢复之前的后台数据,还好Blog已经全部生成为HTML文件。现在重新部署Blog时,索性安装Ubentu Linux和Mezzanine将网站从Perl后台迁移到Python。* * NGINX - public facing web server
* gunicorn - internal HTTP application server
* PostgreSQL - database server
* memcached - in-memory caching server
* supervisord - process control and monitor
* virtualenv - isolated Python environments for each project
* git or mercurial - version control systems (optional)
 
Installation
The easiest method is to install directly from pypi using pip by running the command below, which will also install the required dependencies mentioned above:
pip install mezzanine
Install python3 and pip3.
apt-get install python3
apt-get install python3-pip
pip3 install mezzanine
 
Install PGadmin
apt-get install pgadmin3
 
Once installed, the command mezzanine-project can be used to create a new Mezzanine project in similar fashion to django-admin.py:
cd /var/www
mezzanine-project liaojlweb
cd liaojlweb
 
Configuration
Configurable variables are implemented in the project’s liaojlweb/local_settings.py module. Here’s an example, that leverages some existing setting names:
FABRIC = {
    "DEPLOY_TOOL": "rsync",  # Deploy with "git", "hg", or "rsync"
    "SSH_USER": "liaojl",  # VPS SSH username
    "HOSTS": ["localhost"],  # The IP address of your VPS
    "DOMAINS": ["pshasv-itweb01p.ptcnet.ptc.com"],  # Will be used as ALLOWED_HOSTS in production
    "REQUIREMENTS_PATH": "requirements.txt",  # Project's pip requirements
    "LOCALE": "en_US.UTF-8",  # Should end with ".UTF-8"
    "DB_PASS": "root",  # Live database password
    "ADMIN_PASS": "abc123",  # Live admin user password
    "SECRET_KEY": SECRET_KEY,
    "NEVERCACHE_KEY": NEVERCACHE_KEY,
}
Deploy
fab all
After deploy.
liaojl@pshasv-itweb01p:~$ cd mezzanine/liaojlweb/liaojlweb/
If you see Nginx 502 Bad Gateway Error, change Allow hosts local_settings.py
ALLOWED_HOSTS = ['pshasv-itweb01p.ptcnet.ptc.com']
To include subdomains , add "." at start
ALLOWED_HOSTS = ['.liaojl.com',]
Markdown Support
Get the package
cd ~/.virtualenvs/liaojlweb/bin/
source activate
pip install mezzanine-mdown  # install on virtual env, no need sudo
Setting.
#####################
# MARKDOWN SETTINGS #
#####################
RICHTEXT_WIDGET_CLASS = 'mdown.forms.WmdWidget'
RICHTEXT_FILTERS = ['mdown.filters.codehilite',]

Pagedown WYSIWYG editor

Include 
sudo pip install mezzanine-pagedown Pygments
fab pip install mezzanine-pagedown Pygments
Copy INSTALLED_APPS section from settings.py to local_settings.py. add mezzanine-mdown.
INSTALLED_APPS = ( 
    "mezzanine_pagedown",  # add here.
    "django.contrib.admin", 
    "django.contrib.auth",
    ... ...
Add pagedown settings.
#####################
# PAGEDOWN SETTINGS #
#####################
RICHTEXT_WIDGET_CLASS = 'mezzanine_pagedown.widgets.PageDownWidget'
RICHTEXT_FILTERS = ['mezzanine_pagedown.filters.codehilite',]
PAGEDOWN_MARKDOWN_EXTENSIONS = ('extra','codehilite','toc')
RICHTEXT_FILTER_LEVEL = 3 
PAGEDOWN_SERVER_SIDE_PREVIEW = False
 
edit urls.py
import mezzanine_pagedown.urls
 
add before default url ("^", include("mezzanine.urls")),
    # Pagedown
    url("^pagedown/", include(mezzanine_pagedown.urls)),