PythonãšDjangoãã¬ãŒã ã¯ãŒã¯ã®å€§ãã¡ã³ãšããŠãæ°ããWebãããžã§ã¯ãã®éçºãããéãããã䟿å©ã«ãããœãªã¥ãŒã·ã§ã³ãåžžã«æ¢ããŠããŸããã
Djangoéçºã«ç²ŸéããŠãã人ãªã誰ã§ããçŽæçãªç®¡çããã«ãæ§ç¯ããã®ãã©ãã»ã©äžäŸ¿ãç¥ã£ãŠããŸãã 倧人æ°ã®WordPressã¯éåžžã«é ããããWebãµã€ãéçºã«åå
¥ããããã®åºæºã¯PHPãã¬ãŒã ã¯ãŒã¯ãCMSãããé«ããªã£ãŠããŸãã
ããŸããŸãªãœãªã¥ãŒã·ã§ã³ãé·æéæ€çŽ¢ããŠãã¹ãããåŸãèªåã«æé©ãªãªãã·ã§ã³ã§ãã
Wagtail CMSãèŠã€ããŸãã
ãWagtailã¯ãããŒãããã¯ã¹ã«ãã£ãŠDjangoã§æžãããå®å
šãªCMSã§ãã ã©ããããããšãããããŸãã æ奜家ã®ã³ãã¥ããã£ã«ãã£ãŠãµããŒããããBSDã©ã€ã»ã³ã¹ã®äžã§ãªãªãŒã¹ããããªãŒãã³ãœãŒã¹ãããžã§ã¯ãã
å
žåçãªWagtailã€ã³ã¿ãŒãã§ã€ã¹ã¯æ¬¡ã®ãšããã§ãã
ã»ãã¬ã€ã§ã¯ãã³ã³ãã³ãã®æäœãæ°ããåºçç©ãã»ã¯ã·ã§ã³ã®äœæãç»åã®æäœãéåžžã«äŸ¿å©ã§ãã ãã®ãããžã§ã¯ãã®äžã«ã¯ãå€ãã®èå³æ·±ãæè¡ããããŸãã ããããä»æ¥ã¯ããã«ã€ããŠã§ã¯ãããŸããã
Djangoéçºã®åå¿è
åãã®ç°¡åãªããã°ãç«ã¡äžããæ¹æ³ã®äŸã玹ä»ããŸããéäžã§åŸ
ã¡æ§ããŠããå€ãã®å°é£ãèæ
®ããŸãã
å¿
èŠãªãã®ïŒ
1.å°ãªããšã1 GBã®ã¡ã¢ãªãæèŒããVPS
2. djangoã®åºæ¬çãªçŽ¹ä»
3. Ubuntuããªã¢ãŒãã§æ§æããã¹ãã«
ã¹ããã1ïŒéçºçšã®VPSãµãŒããŒãèµ·åããŸããã Puttyã䜿çšããŠãSSHçµç±ã§ãªã¢ãŒãæ¥ç¶ããŸãã
èšå®ã¯ãUbuntu 14.04ãå®è¡ããŠãããµãŒããŒã§å®è¡ãããŸãã
-ãã°ã€ã³ããŠåºæ¬ã»ããã¢ãããéå§ããŸãã
sudo apt-get update sudo apt-get upgrade
éåžžããµãŒããŒã«ã¯æ¢ã«Python 2ããã³3ããŒãžã§ã³ããããŸãã 次ã®ã³ãã³ãã§ç¢ºèªããŸãã
Python -V Python3 -V
Pillowãšå¿
èŠãªããã€ãã®ã©ã€ãã©ãªãããé©åã«åäœããããããããžã§ã¯ãã«ã¯Python 3ã䜿çšããŸãã
ã©ããããããããµãŒããŒäžã«python3ããªãã£ãå Žåã¯ãã³ãã³ãã§ãããé
眮ããŸãã
sudo apt-get install python3
python3-setuptoolsãšpython3-devãå¿
èŠã§ãã
sudo apt-get install python3-setuptools sudo apt-get install python3-dev
ãã¹ãŠãã¯ãªãŒã³ãªã·ã¹ãã ã«çœ®ãããŠããããšãåæã«ãPIPãèšå®ããŸãïŒã8.1.2ãã®ææ°ããŒãžã§ã³ãã€ã³ã¹ããŒã«ããã«ã¯ãeasy_install3ã䜿çšããããšããå§ãããŸãïŒã
sudo easy_install3 pip
次ã®ã³ãã³ãã§PIPããŒãžã§ã³ã確èªã§ããŸãã
pip -V
ããŒãžã§ã³ãææ°ã§ãªãå Žåã¯ã次ã®ã³ãã³ãã§pipãæŽæ°ããŸãã
sudo pip install --upgrade pip
ä»åŸãWagtailã®ã€ã³ã¹ããŒã«æã«ããŸããŸãªãšã©ãŒãçºçããªãããã«ãPillowã«å¿
èŠãªãã¹ãŠã®ã©ã€ãã©ãªãããã«ã€ã³ã¹ããŒã«ããŸãã
sudo apt-get install libtiff5-dev libjpeg8-dev zlib1g-dev \ libfreetype6-dev liblcms2-dev libwebp-dev tcl8.6-dev tk8.6-dev python-tk
ããã§ããããžã§ã¯ãã«ä»®æ³ç°å¢ãå¿
èŠã«ãªããŸããvirtualenv
sudo pip3 install virtualenv
ä»®æ³ãã·ã³ãäœæããŸãã
virtualenv /opt/myenv
/ opt / myenvãã©ã«ããŒã«ç§»åããŠãä»®æ³ç°å¢ãéå§ããŸãã
source bin/activate
ä»®æ³ãã·ã³ãå®è¡ãããŠããããšãæå³ããååïŒmyenvïŒã®è¡ã衚瀺ãããŸãã
(myenv) alex@local.develop.server:/opt/myenv$
ã¹ããã2ïŒäºåèšå®ãå®äºããããWagtail CMSã®ã€ã³ã¹ããŒã«ãšããŒã¿ããŒã¹ã®èšå®ã«é²ã¿ãŸãã
1.ã»ãã¬ã€ãšGunicornãå
¥ããŸãã
sudo pip3 install wagtail gunicorn
2.ããŒã ãšããŠå°æ¥ã®ããã°ãäœæããŸã
wagtail start mysite
3.ããã°ãã©ã«ããŒïŒmysiteïŒã«ç§»åããrequirements.txtãã¡ã€ã«ãããããžã§ã¯ãã®ãã¹ãŠã®äŸåé¢ä¿ãã€ã³ã¹ããŒã«ããŸã
cd mysite pip install -r requirements.txt
4.ãã®æ®µéã§ãå°æ¥ã®ããã°çšã«ãã¹ããµãŒããŒã移è¡ããŠããã«èµ·åã§ããŸãã ããããç§ãã¡ã¯ãã¹ãŠãæ£ããè¡ãããšãèšç»ããŠãããããããã°ã¯PostgreSQLã§åäœããŸãïŒdjangoã®å ŽåãMySQLãPostgreSQLãOracle DBãªã©ãå«ãããŸããŸãªããŒã¿ããŒã¹ã䜿çšã§ããŸãïŒã ãããã£ãŠãããŒã¿ããŒã¹ãã»ããã¢ããããŠããŸãã
sudo apt-get install libpq-dev sudo apt-get install postgresql postgresql-contrib
5.çŸæç¹ã§ã¯ããã§ã«ããŒã5432ã§postgresqlãèµ·åããŠããŸããããããããŒã¿ããŒã¹ãWagtailãšå¯Ÿè©±ããã«ã¯ãpsycopg2ãã€ã³ã¹ããŒã«ããå¿
èŠããããŸãã
pip install psycopg2
6.ããã§ããããžã§ã¯ãçšã®ããŒã¿ããŒã¹èªäœãäœæããå¿
èŠããããŸãããã®ãããpostgresãŠãŒã¶ãŒã®äžã§è¿œå èšå®ãè¡ããŸãã
sudo su â postgres createdb myblog
7. postgresqlã¯ãã¹ã¯ãŒããèŠæ±ããã«ãŠãŒã¶ãŒãäœæãããããpsqlã䜿çšããŠãŠãŒã¶ãŒã«ãã¹ã¯ãŒããå²ãåœãŠãå¿
èŠããããŸãã
psql
ããã§ããã¹ã¯ãŒãå€æŽã³ãã³ããå®è¡ã§ããŸãã
\password postgres
psqlãçµäºããpostgresãšããŠã»ãã·ã§ã³ãéããŸãã
\q exit
ãŸã ä»®æ³ç°å¢ã«ããããšã確èªããŠãã ãããããã§ãªãå Žåã¯ãä»®æ³ãã·ã³ãå床ã¢ã¯ãã£ãåããŸãã
8.次ã«ãWagtailãèšå®ããŠpostgresqlãšããåãããå¿
èŠããããŸãããã®ããã«ã¯ãbase.pyã«ç§»åããŸãã
cd /opt/myenv/mysite/mysite/settings/ nano base.py
èšå®ãã¡ã€ã«ãéããŸããDATABASESã¬ã³ãŒããå¿
èŠã§ãã æã£ãŠãããã®ãåé€ããããã«ä»¥äžã眮ããŸãïŒ
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2', # , postgresql
'NAME': 'myblog', #
'USER': 'postgres',
'PASSWORD': '******',
'HOST': 'localhost',
'PORT': '',
}
}
ã¡ãªã¿ã«ãã»ãã¬ã€ã¯ãã·ã¢èªã䜿çšããŠãããããèšå®ã§LANGUAGE_CODEãã©ã¡ãŒã¿ãŒãåæã«èª¿æŽã§ããŸãã
LANGUAGE_CODE = 'ru-ru'
å®éãå¿
èŠãªãã¹ãŠã®èšå®ãè¡ã£ãã®ã§ã移è¡ãéå§ã§ããŸãã
ã¹ããã3.æåã®å®è¡
ããã°ã®ã«ãŒããã©ã«ããŒïŒcd / opt / myenv / mysite /ïŒã«ç§»åãããã®ãããžã§ã¯ãã§æåã®ããŒã¿ç§»è¡ãéå§ããŸãã
python manage.py migrate
次ã«ãWagtail管çããã«ã«ç§»åãããŠãŒã¶ãŒãäœæããŸãã
python manage.py createsuperuser
ååïŒããšãã°ãadminïŒããã¹ã¯ãŒããããã³ã¡ãŒã«ãå
¥åããŸãã
ãã¹ãŠãæ©èœããããšã確èªããŸãã
python manage.py runserver 0.0.0.0:8000
VPSã®IPã¢ãã¬ã¹ã®ãã©ãŠã¶ãŒã§ããŒã8000ââïŒäŸ199.199.32.32:8000ïŒã«ç§»åããã»ãã¬ã€éå§ããŒãžã確èªããŸãã
ã§ã¯ã管çããã«199.199.32.32:8000/adminã«ç§»åããåã«äœæãããŠãŒã¶ãŒåãšãã¹ã¯ãŒããå
¥åããŠã䟿å©ãªWagtail CMSã€ã³ã¿ãŒãã§ãŒã¹ã«å
¥ããŸãã
ãããŸã§ã®ãšãããç§ãã¡ã®ãµã€ãã¯ãã®æ¹ââæ³ãç¥ããŸããããããã«ããã°ã«å¿
èŠãªãã®ãã¹ãŠãæããŸãã
ã¹ããã4.ãµã€ãã®éå§ããŒãžãã»ããã¢ãããã
ããŒã ã¢ããªã±ãŒã·ã§ã³ã¯ãããã«äœ¿çšã§ããã¡ã€ã³ããŒãžãæ
åœããŸãã ã¹ã¿ãŒãããŒãžãå¿
èŠãªæ¹æ³ã«ããããã«ãã³ãŒãã«ããã€ãã®å€æŽãå ããŸãã
ãµã€ãã®æ§é ã¯æ¬¡ã®ããã«ãªããŸãã
mysite/
home/
migrations/
__init__.py
0001_initial.py
0002_create_homepage.py
templates/
home/
home_page.html
__init__.py
models.py
search/
templates/
search/
search.html
__init__.py
views.py
mysite/
settings/
__init__.py
base.py
dev.py
production.py
static/
css/
mysite.css
js/
mysite.js
templates/
404.html
500.html
base.html
__init__.py
urls.py
wsgi.py
manage.py
requirements.txt
ãã¡ã€ã«ãhome / models.pyãã次ã®ããã«ç·šéããŸãã
from __future__ import unicode_literals from django.db import models from wagtail.wagtailcore.models import Page from wagtail.wagtailcore.fields import RichTextField from wagtail.wagtailadmin.edit_handlers import FieldPanel class HomePage(Page): body = RichTextField(blank=True) content_panels = Page.content_panels + [ FieldPanel('body', classname="full") ]
ãŸãããã¡ã€ã«home / templates / home / home_page.htmlãç·šéããŸãã
{% extends "base.html" %}
{% load wagtailcore_tags %}
{% block body_class %} template-homepage {% endblock %}
{% block content %}
{{ page.body | richtext }}
{% endblock %}
æ°ããå€æŽãæå¹ã«ããã«ã¯ã移è¡ããŠãã ããïŒ
python manage.py makemigrations python manage.py migrate
ãã®åŸã管çããã«ã«ç§»åããŠãã¹ã¿ãŒãããŒãžã®ããã¹ããç·šéã§ããŸãã
å€æŽãä¿åããŠããµã€ããå床éããŸãã 次ã®ãããªããã¹ãã衚瀺ãããŸãã
ãŸã第äžã«ãæªãã¯ãããŸããããCSSããŒã¯ã¢ãããšçŸãããè¿œå ããå¿
èŠããããŸãã
mysite / settings / base.pyã«ããbase.htmlãã¡ã€ã«ã¯ãåºæ¬çãªãã³ãã¬ãŒããæ
åœããŸãã
cssã®å Žåãmysite / static / css / mysite.cssã«ãããmysite.cssããæ
åœããŸãã
jsã®å Žåãmysite / static / js / mysite.jsã«ãããmysite.jsããæ
åœããŸãã
ç§ã¯ãããªã¢ã©ã€ãºã®ãã¡ã³ã§ããç§ãã¡ã®ãµã€ãã§ã¯ããã³ãã¬ãŒããšã©ã€ãã©ãªããããããååŸããŸãã
ãã¡ã
http://materializecss.com/getting-started.htmlãã芧ãã ããbase.htmlã«æ¬¡ã®å€æŽãå ããŸãã
{% load static wagtailuserbar %} <!DOCTYPE html> <html class="no-js"> <head> <meta charset="utf-8" /> <meta http-equiv="X-UA-Compatible" content="IE=edge" /> <title>{% block title %}{% if self.seo_title %}{{ self.seo_title }}{% else %}{{ self.title }}{% endif %}{% endblock %}{% block title_suffix %}{% endblock %}</title> <meta name="description" content="" /> <meta name="viewport" content="width=device-width, initial-scale=1" /> {# Global stylesheets #} <link rel="stylesheet" type="text/css" href="{% static 'css/mysite.css' %}"> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/0.97.6/css/materialize.min.css"> {% block extra_css %} {# Override this in templates to add extra stylesheets #} {% endblock %} </head> <body class="{% block body_class %}{% endblock %}"> <nav class="light-blue lighten-1" role="navigation"> <div class="nav-wrapper container"><a id="logo-container" href="#" class="brand-logo">Logo</a> <ul class="right hide-on-med-and-down"> <li><a href="#">Navbar Link</a></li> </ul> <ul id="nav-mobile" class="side-nav"> <li><a href="#">Navbar Link</a></li> </ul> <a href="#" data-activates="nav-mobile" class="button-collapse"><i class="material-icons">menu</i></a> </div> </nav> {% wagtailuserbar %} <div class="container"> {% block content %}{% endblock %} </div> <footer class="page-footer orange"> <div class="container"> <div class="row"> <div class="col l6 s12"> <h5 class="white-text">Company Bio</h5> <p class="grey-text text-lighten-4">We are a team of college students working on this project like it's our full time job. Any amount would help support and continue development on this project and is greatly appreciated.</p> </div> <div class="col l3 s12"> <h5 class="white-text">Settings</h5> <ul> <li><a class="white-text" href="#!">Link 1</a></li> <li><a class="white-text" href="#!">Link 2</a></li> <li><a class="white-text" href="#!">Link 3</a></li> <li><a class="white-text" href="#!">Link 4</a></li> </ul> </div> <div class="col l3 s12"> <h5 class="white-text">Connect</h5> <ul> <li><a class="white-text" href="#!">Link 1</a></li> <li><a class="white-text" href="#!">Link 2</a></li> <li><a class="white-text" href="#!">Link 3</a></li> <li><a class="white-text" href="#!">Link 4</a></li> </ul> </div> </div> </div> <div class="footer-copyright"> <div class="container"> Made by <a class="orange-text text-lighten-3" href="http://materializecss.com">Materialize</a> </div> </div> </footer> <script src="https://code.jquery.com/jquery-2.1.1.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/materialize/0.97.6/js/materialize.min.js"></script> {# Global javascript #} <script type="text/javascript" src="{% static 'js/mysite.js' %}"></script> {% block extra_js %} {# Override this in templates to add extra javascript #} {% endblock %} </body> </html>
ãµã€ããä¿åããŠå床éããŸãã 次ã®å³ã®ãããªãã®ã«ãªãã¯ãã§ãã
ãã§ã«è¯ãã 次ã«ããã¹ãŠãéå§ãããããã°ãäœæããå¿
èŠããããŸãã
ã¹ããã5.ããã°ãäœæããŸãã
ãããžã§ã¯ãã®ã«ãŒãã«æ»ãã次ã®ã³ãã³ããå®è¡ããŸãã
python manage.py startapp blog
ãã®åŸãæ°ãããããã°ãã¢ããªã±ãŒã·ã§ã³ãmysite / settings / base.pyã®INSTALLED_APPSã«è¿œå ããŸãã
ããã°ã®åãšã³ããªã«ã¯ãèŠåºããæ¥ä»ãåçã玹ä»ãæ¬æãªã©ã®æšæºãã£ãŒã«ãããããŸãã ãããæ©èœãããã«ã¯ããblog / models.pyãã«æ¬¡ã®å€æŽãå ããŸã
from django.db import models from wagtail.wagtailcore.models import Page from wagtail.wagtailcore.fields import RichTextField from wagtail.wagtailadmin.edit_handlers import FieldPanel from wagtail.wagtailimages.edit_handlers import ImageChooserPanel from wagtail.wagtailsearch import index class BlogPage(Page): main_image = models.ForeignKey( 'wagtailimages.Image', null=True, blank=True, on_delete=models.SET_NULL, related_name='+' ) date = models.DateField("Post date") intro = models.CharField(max_length=250) body = RichTextField(blank=True) search_fields = Page.search_fields + [ index.SearchField('intro'), index.SearchField('body'), ] content_panels = Page.content_panels + [ FieldPanel('date'), ImageChooserPanel('main_image'), FieldPanel('intro'), FieldPanel('body'), ]
次ã«ãããŒãžèªäœãäœæããŸãããã®ãã¹ãŠã®ããŒãžããããã°/ãã³ãã¬ãŒã/ããã°/ blog_page.htmlã«è¡šç€ºãããŸãã
{% extends "base.html" %}
{% load wagtailcore_tags wagtailimages_tags %}
{% block body_class %}template-blogpage{% endblock %}
{% block content %}
{{ page.title }}
{{ page.date }}
{% if page.main_image %}
{% image page.main_image width-500 %}
{% endif %}
{{ page.intro }}
{{ page.body|richtext }}
{% endblock %}
{% extends "base.html" %}
{% load wagtailcore_tags wagtailimages_tags %}
{% block body_class %}template-blogpage{% endblock %}
{% block content %}
{{ page.title }}
{{ page.date }}
{% if page.main_image %}
{% image page.main_image width-500 %}
{% endif %}
{{ page.intro }}
{{ page.body|richtext }}
{% endblock %}
{% extends "base.html" %}
{% load wagtailcore_tags wagtailimages_tags %}
{% block body_class %}template-blogpage{% endblock %}
{% block content %}
{{ page.title }}
{{ page.date }}
{% if page.main_image %}
{% image page.main_image width-500 %}
{% endif %}
{{ page.intro }}
{{ page.body|richtext }}
{% endblock %}
{% extends "base.html" %}
{% load wagtailcore_tags wagtailimages_tags %}
{% block body_class %}template-blogpage{% endblock %}
{% block content %}
{{ page.title }}
{{ page.date }}
{% if page.main_image %}
{% image page.main_image width-500 %}
{% endif %}
{{ page.intro }}
{{ page.body|richtext }}
{% endblock %}
{% extends "base.html" %}
{% load wagtailcore_tags wagtailimages_tags %}
{% block body_class %}template-blogpage{% endblock %}
{% block content %}
{{ page.title }}
{{ page.date }}
{% if page.main_image %}
{% image page.main_image width-500 %}
{% endif %}
{{ page.intro }}
{{ page.body|richtext }}
{% endblock %}
ä»ã®ãšããäœãæ©èœããŠããªãã®ã§ãã³ãã³ããå®è¡ããŸã
python manage.py makemigrations python manage.py migrate
ããã§ã䟿å©ãªã»ãã¬ã€ã€ã³ã¿ãŒãã§ãŒã¹ãéããŠãããã°ã®æåã®ãšã³ããªãäœæã§ããŸãã
管çããã«ã«ç§»åããããšã¯ã¹ãããŒã©ãŒããéããã¡ã€ã³ããŒãžãéžæããŠããåããŒãžãè¿œå ããã¯ãªãã¯ãããšãäœæããããŒãžã®ãã³ãã¬ãŒããéžæãã次ã®ãŠã£ã³ããŠã衚瀺ãããŸãã
ãããã°ããŒãžããéžæããããŒãžã«æ
å ±ãå
¥åããŸãã
ããã¯ãagã®ç®¡çããã«ã§ããã°ããŒãžãç·šéããäŸã§ãã
ãšãŠã䟿å©ã§éãã
ã¬ã³ãŒããä¿åãããã©ãŠã¶ã§éããŸãã ããã°ã®æåã®æçš¿ã®æºåãã§ããŸããã
å°ãªããšã誰ãããã®æçš¿ã䟿å©ã ãšæãå Žåã¯ãã»ãã¬ã€ã®ãããã¯ã«é¢ããæçš¿ãå
¬éãç¶ããŸãããã®ãããã¯ã§ã¯ããã®CMSã®ããŸããŸãªæ©èœã«ã€ããŠè©³ãã説æããŸãã
ããŒã2ããŒã3é¢å¿ã®ãããã¹ãŠã®Wagtail CMSïŒ
å
¬åŒãµã€ã
https://wagtail.io/Githubãããžã§ã¯ã
https://github.com/torchbox/wagtail/ããã¥ã¡ã³ã
http://docs.wagtail.io/en/latest/index.htmlåŠç¿çšã®ãã¢ãµã€ã
http://docs.wagtail.io/en/latest/getting_started/demo_site.htmlãŠãŒã¶ãŒãµããŒãã°ã«ãŒã
https://groups.google.com/forum/#!forum/wagtail