MeidokonWiki:

This is a big dump of old notes from my trying things out.

Yes there are passwords here. It doesn't matter because they're all dead, all these attempts ended in failure and I blew everything away afterwards.

Wagtail

https://docs.wagtail.io/en/stable/getting_started/tutorial.html

mkdir -p ~/public_html/rant.meidokon.net/wagtail
cd ~/public_html/rant.meidokon.net/wagtail/
sudo apt install python3.8-venv
python -m venv venv

. ~/public_html/rant.meidokon.net/wagtail/venv/bin/activate
pip install wagtail

# Initialise new site
wagtail start mysite

# Install deps
cd mysite/
pip install -r requirements.txt

# Prep DB
python manage.py migrate

# Setup user
python manage.py createsuperuser
# furinkan // rah.tzr.gzk5MGK1cvk

# Run it, pushing aside Writefreely for the moment
python manage.py runserver 127.0.0.1:9081
https://rant.meidokon.net/

Mezzanine

Then I tried Mezzanine, another CMS/blog.

# make a new venv, activate it

mkdir -p ~/public_html/rant.meidokon.net/mezzanine
cd ~/public_html/rant.meidokon.net/mezzanine/
sudo apt install python3.8-venv

python -m venv venv
. venv/bin/activate
pip install wheel
pip install Django==2.2.8

#pip install mezzanine
#pip install https://github.com/stephenmcd/mezzanine/archive/refs/heads/master.zip
pip install Mezzanine==5.0.0a1

mezzanine-project myproject
cd myproject

python manage.py createdb

python manage.py runserver 127.0.0.1:9081

fix up myproject/local_settings.py

At the time of writing these notes (Aug 2021), the quickstart guide on Mezzanine's homepage simply does not work, it's quite broken.

Zinnia

Zinnia seemed promising, but it was unmaintained and their demo site had been infected or hijacked with something nasty.

venv

New venv, activate it

Clone git repo, cd there

python setup.py install

Now we have a bleeding edge version installed in our environment.

pip install wheel
apt install libpq-dev
pip install psycopg2

prepare DB

furinkan // xpj2BWV5qaz8fzb.mcq

postgres@suomi:~$ createuser --echo --pwprompt furinkan
Enter password for new role: 
Enter it again: 
SELECT pg_catalog.set_config('search_path', '', false);
CREATE ROLE furinkan PASSWORD 'md5e4265ae16636fbcd284aa47e8c9cd121' NOSUPERUSER NOCREATEDB NOCREATEROLE INHERIT LOGIN;

postgres@suomi:~$ createdb --echo --encoding=UTF8 --owner=furinkan rant_meidokon "Blog at rant.meidokon.net"
SELECT pg_catalog.set_config('search_path', '', false);
CREATE DATABASE rant_meidokon OWNER furinkan ENCODING 'UTF8';
COMMENT ON DATABASE rant_meidokon IS 'Blog at rant.meidokon.net';

setup django project

django-admin startproject rant

cd into rant/

configure rant/settings.py

# populate DB
./manage.py migrate

./manage.py runserver

wrangle secrets

Put them outside the settings file, eg. /home/furinkan/git/rant/deployment_secrets.py

Then in /home/furinkan/git/rant/rant/settings.py you can do import deployment_settings

customisation

pip install markdown

mkdir -p templates/zinnia

Add
BASE_DIR / 'templates',
to the TEMPLATES['DIRS'] in settings.py (literally as shown, it's hax)

Create the django superuser

furinkan // fric@whus9joss6SUCH
fric@whus9joss6SUCH

Try adding a nice theme, this seemed kinda promising that they even have themes: https://github.com/django-blog-zinnia/zinnia-theme-foundation

pip install git+git://github.com/django-blog-zinnia/zinnia-theme-foundation.git

Fix up templates loader as directed, and install the loader from pip:

pip install django-app-namespace-template-loader

Fixes

Ran into this problem, I had to fix 3 templates: https://stackoverflow.com/questions/55929472/django-templatesyntaxerror-staticfiles-is-not-a-registered-tag-library

Lock it down for deployment

Should do this: https://docs.djangoproject.com/en/3.2/howto/deployment/checklist/

Puput

Latest

Try to run latest version of Puput.

New venv, activate it, install wheel

. ~/venvs/puput/bin/activate

pip install puput  # this gets django 3.0.14 and wagtail 2.14.1

django-admin startproject puputrant
cd puputrant
python manage.py migrate

Edit settings.py and append PUPUT_APPS

and I've just found a new DB problem: https://stackoverflow.com/questions/68024060/assertionerror-database-connection-isnt-set-to-utc

This may be due to the order that I've installed and migrated the server. Again. :/

// use this requirement as a preinstall
psycopg2>=2.8,<2.9

Try with stricter versions

pip install 'Django>=2.2,<3.0'
pip install 'wagtail>=2.7,<2.14'
pip install puput

We now have django 2.2.24, wagtail 2.13.4, puput 1.1.1

django-admin startproject puputrant2
cd puputrant2
python manage.py migrate

// edit settings.py and append PUPUT_APPS

// middleware stuff is wrong? I used this last time
'wagtail.contrib.legacy.sitemiddleware.SiteMiddleware',
'wagtail.contrib.redirects.middleware.RedirectMiddleware',

Stumble through rest of guide https://puput.readthedocs.io/en/latest/setup.html

./manage.py createsuperuser
./manage.py runserver 0:8081

furinkan // fric@whus9joss6SUCH

A clean working attempt

Okay let's document the whole thing from scratch, so it's reproducible.

This should be kinda copypasta-able, so when you screw it up you can just blow it away and try again with minimal effort.

deactivate
rm -rf ~/venvs/rant
pip cache purge
python -m venv ~/venvs/rant
. ~/venvs/rant/bin/activate
pip install wheel

pip install 'Django>=2.2,<3.0'
pip install 'wagtail>=2.7,<2.14'
pip install 'psycopg2>=2.8,<2.9'
pip install puput

pip install 'Django>=2.2,<3.0' 'wagtail>=2.7,<2.14' 'psycopg2>=2.8,<2.9' --no-cache-dir
pip install puput==1.1.1 --no-cache-dir  # this just happens to be the current version

We now have django 2.2.24, wagtail 2.13.4, puput 1.1.1, psycopg2 2.8.6

Clean database up now

sudo -u postgres createuser --echo --pwprompt furinkan
sudo -u postgres dropdb rant_meidokon
sudo -u postgres -- createdb --echo --encoding=UTF8 --owner=furinkan rant_meidokon "Blog at rant.meidokon.net"

Setup the django project

cd ~/git/
rm -rf ~/git/rant/
django-admin startproject rant
cd rant/

Now do DB and TZ setup in settings.py

cp ../deployment_secrets.py ./
vim rant/settings.py
import deployment_secrets
TIME_ZONE = 'Australia/Sydney'
        'ENGINE': 'django.db.backends.postgresql_psycopg2',
        'NAME': 'rant_meidokon',
        'USER': deployment_secrets.DB_USER,
        'PASSWORD': deployment_secrets.DB_PASS,

Create data structures in the DB

python manage.py migrate
python manage.py createsuperuser

# furinkan // fric@whus9joss6SUCH

And try running it now:

python manage.py runserver 0.0.0.0:8081

Edit settings.py according to docs, adding this

from puput import PUPUT_APPS
INSTALLED_APPS += PUPUT_APPS

Try runserver, see it suggests migrating. So migrate now:

python manage.py migrate

Try runserver again and it works fine? Okay let's keep going.

Well, runserver works again, so let's try the next step. Set the WAGTAIL_SITE_NAME variable, this shouldn't break anything.

WAGTAIL_SITE_NAME = 'Meidokon Rants'

Now setup some minimal urlpatterns:

import puput
from django.contrib import admin
from django.urls import path
from django.urls import include

urlpatterns = [
    path('admin/', admin.site.urls),
    path('', include(puput.urls)),
]

And with any luck, it might even work now??!?

Nope no code highlighting

Some random links, the first two relate to code highlighting. I dunno why I have the third one:

Migrations

I don't know why I have this noted down either.

activate rant venv
cd /home/furinkan/git/rant
python manage.py runserver 0.0.0.0:8081


add migration modules to rant/settings.py
    MIGRATION_MODULES = {'puput': 'rant.puput_migrations'}
makemigrations puput
add/edit rant/models.py
makemigrations again

Bulma

Alright let's try this one: https://github.com/Pei2tech/Django-Puput-Bulma-Demo

Notes made on 2021-09-25

Install

deactivate
rm -rf ~/venvs/bulma
pip cache purge
python -m venv ~/venvs/bulma
. ~/venvs/bulma/bin/activate
pip install wheel

pip install Django==3.0.14 puput==1.1.1 wagtail-markdown==0.7.0 Unidecode==1.2.0 'psycopg2>=2.8,<2.9' --no-cache-dir

# We now have:
#   Django 3.0.14
#   Wagtail 2.14.1 (happens to be latest?)
#   Puput 1.1.1 (happens to be latest)
#   Psycopg2 2.8.6

Clean up database

sudo -u postgres createuser --echo --pwprompt furinkan
sudo -u postgres dropdb bulma
sudo -u postgres -- createdb --echo --encoding=UTF8 --owner=furinkan bulma "Blog using bulma"

Setup django project

cd ~/git/
rm -rf ~/git/bulma/
git clone https://github.com/Pei2tech/Django-Puput-Bulma-Demo.git bulma
cd bulma/Myblog/

# Now do DB and TZ setup in settings.py
cp ../deployment_secrets.py ./
vim rant/settings.py
import deployment_secrets
TIME_ZONE = 'Australia/Sydney'
        'ENGINE': 'django.db.backends.postgresql_psycopg2',
        'NAME': 'rant_meidokon',
        'USER': deployment_secrets.DB_USER,
        'PASSWORD': deployment_secrets.DB_PASS,

Create data structures

python manage.py migrate
python manage.py createsuperuser

# furinkan // fric@whus9joss6SUCH

python manage.py runserver 0.0.0.0:8081

Edit settings.py according to docs

from puput import PUPUT_APPS
INSTALLED_APPS += PUPUT_APPS

# try runserver, see it suggests migrating. So migrate now
python manage.py migrate

# runserver again and it works fine, let's keep going
# add two lines to MIDDLEWARE, test again
# fails, because the dot paths are wrong. try the contrib, which became a thing in wagtail 2.11(?)
# https://docs.wagtail.io/en/v2.11.2/releases/2.11.html?highlight=SiteMiddleware#sitemiddleware-moved-to-wagtail-contrib-legacy
# Good to know this is a deprecated thing too...
    'wagtail.contrib.legacy.sitemiddleware.SiteMiddleware',
    'wagtail.contrib.redirects.middleware.RedirectMiddleware',

runserver works again, let's try the next step

# Set the WAGTAIL_SITE_NAME variable
WAGTAIL_SITE_NAME = 'Meidokon Rants'

# Set minimal urlpatterns
import puput
from django.contrib import admin
from django.urls import path
from django.urls import include

urlpatterns = [
    path('admin/', admin.site.urls),
    path('', include(puput.urls)),
]

MeidokonWiki: furinkan/IWantedAPythonBlog (last edited 2022-03-18 03:31:20 by furinkan)