Prologue

One of my friend began a weblog with WordPress, then I thought...

I wanna move my weblog from rental weblog to my own server, to have my own site as well.
As I do programming, I have to create weblog system from the beginning by myself!

And then it got a big project and took more than months. During the development many of personal weblogs helped me so really much. I also try to note know-hows that I learned.

The most troublesome thing in Django development was surely to create environment. So I start writing about it first.

 

What we have to know before start

I'm not the only person having a lot of problems around environment. Many people shout like below.

  • Django doesn't work on production env even though it does on development env!
  • Cannot display images on production env!
  • But no errors are displayed!
  • Does anyone know how to display errors on production env????

They were all my shout as well tho. These problems originate from the difference of ways to operate between on development env and on production env.

Django テスト環境と本番環境の違い

As you see, Django delivers all contents as they are on development env. While on production env, the way to deliver errors and static files is different. That's why it doesn't work on production env even if our codes have no problem on development env.

Boot script is different at first! It's manage.py on development env while wsgi.py is on production env. It confused me. So we have to take steps below to understand and to resolve problems.

  • Get how to boot Django through wsgi.py not manage.py
  • Get how to display static files
  • Get how to display error

 

Environment to resolve them

  • Vagrant, Virtualbox
  • CentOS7
  • Apache
  • MySQL
  • Python3.6
  • Django2.1.8
  • (Mac High Sierra)

We will prepare CentOS7 as virtual machine on local PC and develop with the setting for production env(DEBUG = False). When we know how to see error and to display static files, there is no need for us to operate with DEBUG = True.