Project Layout

  1. Start your project by following the Django official tutorial:

    django-admin startproject firsthomework **#firsthomework is whatever you name your project**

    Download the docker-v2.zip file from the class Canvas page (posted with HW #1) and unzip it.  (It may be easier to download to your computer, then scp to your vm, then unzip)

  2. You will get a brand new directory named "firsthomework". You basically need to move everything out of that directory. The correct project layout should be:

    docker-deploy
       |—docker-compose.yml
       |—nginx
       |     |—config
       |            |—web-app.conf
       |—web-app
             |—Dockerfile
             |—requirements.txt
             |—runserver.sh
             |—initserver.sh
             |—startserver.sh
             |—manage.py
             |—firsthomework
                   |—urls.py
                   |—settings.py
                   |—other stuff..
             |....all your other directories for the project... (basically it will be the app directory once you create the app)
    
  3. To make things consistent, be aware of which version of Django you're using.

    You should change this line in the "requirements.txt" from Django>=2.0,<3.0 to Django>3.0

  4. To use docker, you must change the permission of the “runserver.sh” script in the "web-app" directory. To do this, go to the "web-app" directory and type this command:

    chmod o+x runserver.sh

    Some have reported needing to do this command (’chmod u+x’) for the other *.sh files as well (initserver.sh, startserver.sh). So you could also do this command to be safe:

    chmod o+x *.sh

Database

How to setup a local Postgres database?

  1. For HW1, you will use Postgres as the database, not SQLite.
  2. You are also allowed to use some cloud Postgres ****DB, which might save some trouble - like what is explained in this video.

How to setup the database in Docker?

A local database is easier to debug, but please remember to use the database in Docker before submission.

see Project Submission Requirement

Docker

  1. Q: have trouble starting the server in docker

    A: It's possibly related to the permission of starting script. You can use chmod o+x runserver.sh chmod o+x initserver.sh to change.

  2. DB in docker (why we add 'web' to ALLOWED_HOSTS? how to change the database settings while running the program inside docker?)

    & how to debug in docker?

    About Database Setting And Docker

  3. Having database problems moving to Docker?

IDE