CRUD with Django, PostgreSQL, Bootstrap and Heroku —Part 1: Django initial setup
Tags: Postgresql, Django, Web Development, Python, Crud

If you’re a newbie, you must be asking yourself: what the fuck does Django have to do with Django framework? The answer is: nothing. But it’s quite a funny preview picture for this article.

This tutorial is most likely oriented for all those guys who have had struggle configuring CRUD (Create, Read, Update and Delete) operations with Django and deploying the apps on Heroku as well.

Let’s get started.

It’s always a good practice to encapsulate all your libraries on a environment variable. I’d suggest you to use Anaconda for this. If you’re already familiar with this, go ahead.

First, we’ll create an environment variable with Anaconda.

conda create -n django-crud-app python=3.6

Once we created our env variable, we activate it and install Django.

conda activate django-crud-app

pip install django

Then, we start our new project.

django-admin startproject employee_project

We should have a similar project structure as the following:

Django basic project structure

Then, we run the Django server for the first time. If everything is okay, we’ll see the default welcome page.

python manage.py runserver

Output:



Performing system checks...



System check identified no issues (0 silenced).



You have 17 unapplied migration(s). Your project may not work properly until you apply the migrations for app(s): admin, auth, contenttypes, sessions.

Run 'python manage.py migrate' to apply them.



May 21, 2020 - 20:45:39

Django version 3.0.6, using settings 'employee_project.settings'

Starting development server at

Quit the server with CONTROL-C.

[21/May/2020 20:45:54] "GET / HTTP/1.1" 200 16351

[21/May/2020 20:45:54] "GET /static/admin/css/fonts.css HTTP/1.1" 200 423

Not Found: /favicon.ico

[21/May/2020 20:45:54] "GET /favicon.ico HTTP/1.1" 404 1982

[21/May/2020 20:45:54] "GET /static/admin/fonts/Roboto-Regular-webfont.woff HTTP/1.1" 200 85876

[21/May/2020 20:45:54] "GET /static/admin/fonts/Roboto-Bold-webfont.woff HTTP/1.1" 200 86184

[21/May/2020 20:45:54] "GET /static/admin/fonts/Roboto-Light-webfont.woff HTTP/1.1" 200 85692 Watching for file changes with StatReloaderPerforming system checks...System check identified no issues (0 silenced).You have 17 unapplied migration(s). Your project may not work properly until you apply the migrations for app(s): admin, auth, contenttypes, sessions.Run 'python manage.py migrate' to apply them.May 21, 2020 - 20:45:39Django version 3.0.6, using settings 'employee_project.settings'Starting development server at http://127.0.0.1:8000/ Quit the server with CONTROL-C.[21/May/2020 20:45:54] "GET / HTTP/1.1" 200 16351[21/May/2020 20:45:54] "GET /static/admin/css/fonts.css HTTP/1.1" 200 423Not Found: /favicon.ico[21/May/2020 20:45:54] "GET /favicon.ico HTTP/1.1" 404 1982[21/May/2020 20:45:54] "GET /static/admin/fonts/Roboto-Regular-webfont.woff HTTP/1.1" 200 85876[21/May/2020 20:45:54] "GET /static/admin/fonts/Roboto-Bold-webfont.woff HTTP/1.1" 200 86184[21/May/2020 20:45:54] "GET /static/admin/fonts/Roboto-Light-webfont.woff HTTP/1.1" 200 85692

If we go to 127.0.0.1:8000…

Succesful initialized Django project

After we succesfully installed Django basic libraries on our env variable, we will create a new app. For this example, we’ll call this new app employee_register.

python manage.py startapp employee_register

We’ll see that our project structure have a new folder with the new app name.

Updated project structure

After creating successfully our new Django app, we’ll append it to the INSTALLED_APPS list, inside employee_project/settings.py file.

....

# Application definition INSTALLED_APPS = [ ..., 'employee_register', ] ....

Django initial setup is ready.

In the next part, we’ll procede to configure the database part of our project with PostgreSQL.