New Socialist website
Switch branches/tags
Nothing to show
Clone or download
dellsystem Fix bugs with index display in mobile view
The first article's photo was being hidden because of an overeager
CSS change I'd made to make the article photo look better on mobile
Latest commit 97a8b93 Nov 16, 2018

New Socialist

Django site for managing an online publication.


Within a virtualenv, run the following commands, in order:

pip install -r requirements.txt
./django/ makemigrations journal cms uploads
./django/ migrate
./django/ createsuperuser
./django/ loaddata initial_fixtures.json


./django/ runserver

You can find the admin interface at http://localhost:8000/sudo/ (for the superuser) or http://localhost:8000/editor/ (the link to give to editors). You can create users with editor permissions via the /sudo/ admin site: set is_staff to True, and give them any necessary permissions (there will be a permission group eventually, but for now you'll have to select them manually).

None of the links in the menu will work. You'll have to create the 4 categories (under the journal app) and the 2 pages (under the cms app).

Deploying in production

To deploy in production with Postgres, a custom secret key, and DEBUG=False, set the following environment variables within the virtualenv:

  • POSTGRES_PASSWORD: the password for PostgreSQL
  • DJANGO_SECRET_KEY: the SECRET_KEY used by Django (set to a random string)
  • ALLOWED_HOST: e.g., ''


Currently running as a systemd service. Create /etc/systemd/system/gunicorn.service:

Description=gunicorn daemon for newsocialist

ExecStart=/path/to/dir/new-socialist/env/bin/gunicorn --access-logfile - --workers 3
--bind unix:/tmp/gunicorn.sock newsocialist.wsgi:application


The variables file should look something like this:


Restart the service by running fab re.


The configuration file should look something like this:

server {
    listen 80;

    if ($host = {
        return 301 https://$host$request_uri;
    } # managed by Certbot

    if ($host = {
        return 301$request_uri;

    return 404; # managed by Certbot

server {
    listen 443 default_server ssl;

    location /favicon.ico {
        alias /path/to/dir/new-socialist/static/favicon.ico;

    location /media/ {
        root /path/to/dir/new-socialist;

    location /static/ {
        root /path/to/dir/new-socialist;

    location / {
        client_max_body_size 15M;
        include proxy_params;
        proxy_pass http://unix:/tmp/gunicorn.sock;

    # for certbot renewal
    location ~ /.well-known {
        root /path/to/dir/new-socialist;
        allow all;

    ssl_certificate /etc/letsencrypt/live/; #
managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/; # managed by Certbot

    # deny illegal host headers to prevent "Invalid HTTP_HOST header" emails
    if ($host !~* ^$ ) {
        return 444;


To send daily commission reminder emails with sendgrid, add this to your crontab:

0 * * * * source /path/to/dir/new-socialist/env/bin/activate && python /path/to/dir/new-socialist/django/ runcrons

(setting the shell to bash is necessary as otherwise source won't work, and source is needed for the activate script to function)