To set up my application I followed Django tutorial. It was pretty straight forward and allowed me to set up my application easily. I’ll write about some stuff which isn’t explicitly covered by tutorial.

When working with python it’s usually a good idea to use virtualenv - it allows to separate environment for each project. I have a separate virtualenv for each of my projects.

After installing Django in my virtualenv for frisor project I had run django-admin startproject frisor which generated a frisor project for me - the most important file genereted by it is When you run $ python you can see available subcommands. I used:

  • $ python startapp to create an application. It’s important to add application to project’s and create url for it in
  • $ python runserver 8080 to start a server on port 8080.
  • $ python migrate - in basic setup it creates sqlite3 database and runs migrations which weren’t applied yet. Applied migrations are stored in django_migrations table in database.

After setting up database and application I created a basic ORM model for urls I want to store in database:

from django.db import models

class Url(models.Model):
    url = models.CharField(max_length=200)
    publish_date = models.DateTimeField('date published')
    title = models.CharField(max_length=200)
    creator = models.CharField(max_length=200)

Django is smart and it can generate migrations for created or updated models. Simply run $ python makemigrations $your-app-name to create migration files. Remember it doesn’t apply migrations - to apply them run again $ python migrate.

Before going public with Django application it’s important to run $ python check --deploy - it helps with security checks. It’s good to look into file and read carefully deployment checklist - the link to this checklist is in one of comments in settings file. From running this command I’ve learnt I should store my secret key in environmental variable (or in a file), so I created a production_settings file which will be also in my .gitignore to prevent accidental publishing. For now my internal settings file looks like:

export SECRET_KEY="############### secret #############"
export DEBUG=True

Maybe later I’ll think about creating an ansible script for deployment, but it’s not necessary for now.

So here is screen from my frisor working draft ;): screenshot

Leave a Comment