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 manage.py
. When you run
$ python manage.py
you can see available subcommands. I used:
$ python manage.py startapp
to create an application. It’s important to add application to project’ssettings.py
and create url for it inurls.py
$ python manage.py runserver 8080
to start a server on port 8080.$ python manage.py migrate
- in basic setup it creates sqlite3 database and runs migrations which weren’t applied yet. Applied migrations are stored indjango_migrations
table in database.
After setting up database and application I created a basic ORM model for urls I want to store in database:
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 manage.py migrate
.
Before going public with Django application it’s important to run $ python manage.py check --deploy
- it
helps with security checks. It’s good to look into settings.py
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:
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 ;):
Leave a Comment