Why does my env variables setted on Travis are equal to None?

I am trying to build a CI with Travis for my docker app. In my docker compose I import a file called “.env”. This file is gitignored so Travis cant use it. To fix the problem, I create the empty file in my .travis.yml file and set the environment variables on the website :

language: python
python:
  - "3.6"

services:
  - docker

before_script:
  - touch .env
  - pip install docker-compose

script:
  - docker-compose run web sh -c "python manage.py test"

When I push on git, everything seem to work Travis side until the test start and Travis come to this line of code in my app :

ALLOWED_HOSTS = os.environ.get("DJANGO_ALLOWED_HOSTS").split(" ")

There I have this error in Travis logs :

  File "/home/pur_beurre/web/pur_beurre/settings.py", line 29, in <module>
    ALLOWED_HOSTS = os.environ.get("DJANGO_ALLOWED_HOSTS").split(" ")
AttributeError: 'NoneType' object has no attribute 'split'
1
The command "docker-compose run web sh -c "python manage.py test"" exited with 1.

Note : DJANGO_ALLOWED_HOSTS = localhost