I'm building this site with Django!

Posted by: Zach Bernal | in testing | 1 year, 2 months ago |

Polishing this website has been something I've needed to do for a while. Originally I wrote this in PHP, back when I was still starting out in college, but I'm sick of coding up my own base templates, gallery modules, blog modules, etc.

This weekend I went through the django beginner's tutorial and installed Mezzanine, along with a free theme from somewhere on github.

Now that I've got the barebones set up, I can start filling out the site with content!

...oh, I should probably figure out how to deploy this thing to the actual web first.

Ok, I'll describe what I did step-by-step.

First, Django for Python 3.6 on my local laptop:

pip install django

I read through the Writing your first Django app tutorial, and created a nice little polls app.


...lol, turns out Mezzanine 4.3.0 (latest) uses Django 1.11, so if I want to run this tutorial again I'll have to convert it or use virtualenv. That's ok, great learning exercise.

Installing Mezzanine locally and creating a new project

pip install Mezzanine

cd F:\ck_website\

mezzanine-project cknet

cd cknet

python manage.py createdb --noinput

python manage.py runserver

Change the admin password so I don't get hacked to bits:


Install a pretty theme and customize it:


changed settings.py to use the solid theme and enable per-blog-post featured images:



SITE_TITLE = 'Zach Bernal'
SITE_TAGLINE = 'Chrisknyfe'

I configured this mezzanine project to use the theme's homepage (urls.py):

# ...
url("^$", direct_to_template, {"template": "index.html"}, name="home"),

I had to deactivate solid/templates/pages/menus/admin.html because it broke adding child pages:

mv admin.html _deactivated_admin.html

I customized the home page, looked through some of the font css for "FontAwesome", turns out it has a bunch of glyphs for popular social media sites! You can create a github link in whatever color you want with:

<i class="fa fa-github-square"></i>

Turns out you can hack around bootstrap's CSS... some of their row/column styles are numbered 1 through 12, basically a scale from 0 to 100% width. Makes things nicely divisible.

Need to update my debian webserver first...

Tutorial used: https://www.pontikis.net/blog/debian-upgrade-wheezy-to-jessie

tar -czf www.tar.gz /var/www

# downloaded that to my laptop

sudo /etc/init.d/apache2 stop
sudo apt-get update
sudo apt-get -V upgrade
sudo nano /etc/apt/sources.list

# switched from using the Debian Wheezy sources to the Debian Jessie sources

sudo apt-get update && sudo apt-get -V upgrade
sudo apt-get dist-upgrade

It was at this point that I ran into this bug: https://bugs.launchpad.net/ubuntu/+source/sysvinit/+bug/1389891

So I deleted /dev/shm and finished the install:

sudo rm /dev/shm
sudo apt-get -f install

...hmm. Looks like Apache got upgraded from 2.2 to 2.4 in the upgrade. I'll need to reconfigure for my existing PHP site first. Looks like these guys have a tutorial: http://httpd.apache.org/docs/2.4/upgrading.html

~$ /usr/sbin/apache2 -v
Server version: Apache/2.4.10 (Debian)
Server built: Mar 31 2018 09:39:03

~$ ls -al /etc/apache2/sites-enabled/
total 8
drwxr-xr-x 2 root root 4096 Nov 22 2014 .
drwxr-xr-x 8 root root 4096 Aug 6 13:03 ..
lrwxrwxrwx 1 root root 33 Nov 21 2014 chrisknyfe.net -> ../sites-available/chrisknyfe.net
lrwxrwxrwx 1 root root 36 Nov 21 2014 flyingislands.net -> ../sites-available/flyingislands.net
lrwxrwxrwx 1 root root 26 Nov 22 2014 redmine -> ../sites-available/redmine
~$ ls -al /etc/apache2/sites-available/
total 36
drwxr-xr-x 2 root root 4096 Aug 6 13:02 .
drwxr-xr-x 8 root root 4096 Aug 6 13:03 ..
-rw-r--r-- 1 root root 962 Nov 21 2014 000-default.conf
-rw-r--r-- 1 root root 1332 Mar 30 11:07 000-default.conf.dpkg-new
-rw-r--r-- 1 root root 1020 Nov 21 2014 chrisknyfe.net
-rw-r--r-- 1 root root 6437 Mar 31 05:17 default-ssl.conf
-rw-r--r-- 1 root root 781 Nov 21 2014 flyingislands.net
-rw-r--r-- 1 root root 22 Nov 22 2014 redmine

I haven't updated this POS since 2014? Yikes.

Looks like I needed to re-enable the sites:

/etc/apache2/sites-enabled$ sudo rm chrisknyfe.net flyingislands.net
/etc/apache2/sites-available$ sudo mv chrisknyfe.net chrisknyfe-net.conf
/etc/apache2/sites-available$ sudo mv flyingislands.net flyingislands-net.conf
/etc/apache2/sites-available$ sudo a2ensite chrisknyfe-net.conf
Enabling site chrisknyfe-net.
To activate the new configuration, you need to run:
service apache2 reload
/etc/apache2/sites-available$ sudo a2ensite flyingislands-net.conf
Enabling site flyingislands-net.
To activate the new configuration, you need to run:
service apache2 reload
/etc/apache2/sites-available$ sudo /etc/init.d/apache2 restart
[ ok ] Restarting web server: apache2.

Installing Mezzanine with Django, Apache2 mod_wsgi, and Debian Jessie

Based on this tutorial: https://www.digitalocean.com/community/tutorials/how-to-serve-django-applications-with-apache-and-mod_wsgi-on-debian-8#configure-apache

sudo apt-get install build-essential python3 python3-pip python3-dev python3 python3-pip libapache2-mod-wsgi-py3

# pillow dependencies. basically throwing in the kitchen sink because pillow ends up building itself from source
sudo apt-get install zlib1g zlib1g-dev libjpeg-dev python-libtiff libfreetype6-dev libwebp-dev tcl tcl-dev libopenjpeg-dev python-imaging

sudo pip3 install mezzanine virtualenv

# upload a copy of my website to /var/www/cknet

cd /var/www/cknet
virtualenv cknetenv
source cknetenv/bin/activate
pip install mezzanine

Edited local_settings.py:

DEBUG = False
ALLOWED_HOSTS = ["chrisknyfe.net", "localhost", "", "::1"]

#already made superuser when I made the local project
python manage.py makemigrations
python manage.py migrate
python manage.py collectstatic

I created a conf file for the apache 2.4 mod_wsgi setup I have at /etc/apache2/sites-available/chrisknyfe-net-mz.conf

<VirtualHost *:80>
ServerAdmin webmaster@localhost
ServerName chrisknyfe.net
ServerAlias www.chrisknyfe.net

DocumentRoot /var/www/cknet/static

Alias /static /var/www/cknet/static

<Directory /var/www/cknet/static>
Require all granted

<Directory /var/www/cknet/cknet>
<Files wsgi.py>
Require all granted

WSGIDaemonProcess cknet python-home=/var/www/cknet/cknetenv python-path=/var/www/cknet
WSGIProcessGroup cknet
WSGIScriptAlias / /var/www/cknet/cknet/wsgi.py

ErrorLog ${APACHE_LOG_DIR}/error_cknet.log

# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel info

CustomLog ${APACHE_LOG_DIR}/access_cknet.log combined

chown -R root:www-data /var/www/cknet/
chmod -R 775 /var/www/cknet/
chmod 664 /var/www/cknet/*db*

sudo /etc/init.d/apache2 restart

And voila! Website up.

Next: security.

Current rating: 5

Recent Posts




testing 2


admin (2) Zach Bernal (1)


RSS / Atom

Template by Blacktie Mezzanine theme by CodingHouse