Having problems trying to set a secret key inside an .env instead of the settings.py file
When I run the heroku config I get the secret key
(portfolio) PS C:\Users\arund\Desktop\Code\Django\portfolio-project> heroku config:get SECRET_KEY
value
When I run the following I get errors.
(portfolio) PS C:\Users\arund\Desktop\Code\Django\portfolio-project> heroku local
[OKAY] Loaded ENV .env File as KEY=VALUE Format
1:53:57 PM web.1 | Traceback (most recent call last):
1:53:57 PM web.1 | File "C:\Users\arund\Desktop\Code\Django\portfolio-project\manage.py", line 22, in <module>
1:53:57 PM web.1 | main()
1:53:57 PM web.1 | File "C:\Users\arund\Desktop\Code\Django\portfolio-project\manage.py", line 18, in main
1:53:57 PM web.1 | execute_from_command_line(sys.argv)
1:53:57 PM web.1 | File "C:\Users\arund\Desktop\Code\Django\portfolio-project\venv\lib\site-packages\django\core\management\__init__.py", line 419, in execute_from_command_line
1:53:57 PM web.1 | utility.execute()
1:53:57 PM web.1 | File "C:\Users\arund\Desktop\Code\Django\portfolio-project\venv\lib\site-packages\django\core\management\__init__.py", line 395, in execute
1:53:57 PM web.1 | django.setup()
1:53:57 PM web.1 | File "C:\Users\arund\Desktop\Code\Django\portfolio-project\venv\lib\site-packages\django\__init__.py", line 24, in setup
1:53:57 PM web.1 | apps.populate(settings.INSTALLED_APPS)
1:53:57 PM web.1 | File "C:\Users\arund\Desktop\Code\Django\portfolio-project\venv\lib\site-packages\django\apps\registry.py", line 122, in populate
1:53:57 PM web.1 | app_config.ready()
1:53:57 PM web.1 | File "C:\Users\arund\Desktop\Code\Django\portfolio-project\venv\lib\site-packages\django\contrib\admin\apps.py", line 27, in ready
1:53:57 PM web.1 | self.module.autodiscover()
1:53:57 PM web.1 | File "C:\Users\arund\Desktop\Code\Django\portfolio-project\venv\lib\site-packages\django\contrib\admin\__init__.py", line 24, in autodiscover
1:53:57 PM web.1 | autodiscover_modules('admin', register_to=site)
1:53:57 PM web.1 | File "C:\Users\arund\Desktop\Code\Django\portfolio-project\venv\lib\site-packages\django\utils\module_loading.py", line 47, in autodiscover_modules
1:53:57 PM web.1 | import_module('%s.%s' % (app_config.name, module_to_search))
1:53:57 PM web.1 | File "C:\Python39\lib\importlib\__init__.py", line 127, in import_module
1:53:57 PM web.1 | return _bootstrap._gcd_import(name[level:], package, level)
1:53:57 PM web.1 | File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
1:53:57 PM web.1 | File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
1:53:57 PM web.1 | File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
1:53:57 PM web.1 | File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
1:53:57 PM web.1 | File "<frozen importlib._bootstrap_external>", line 790, in exec_module
1:53:57 PM web.1 | File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
1:53:57 PM web.1 | File "C:\Users\arund\Desktop\Code\Django\portfolio-project\venv\lib\site-packages\django\contrib\auth\admin.py", line 6, in <module>
1:53:57 PM web.1 | from django.contrib.auth.forms import (
1:53:57 PM web.1 | File "C:\Users\arund\Desktop\Code\Django\portfolio-project\venv\lib\site-packages\django\contrib\auth\forms.py", line 11, in <module>
1:53:57 PM web.1 | from django.contrib.auth.tokens import default_token_generator
1:53:57 PM web.1 | File "C:\Users\arund\Desktop\Code\Django\portfolio-project\venv\lib\site-packages\django\contrib\auth\tokens.py", line 117, in <module>
1:53:57 PM web.1 | default_token_generator = PasswordResetTokenGenerator()
1:53:57 PM web.1 | File "C:\Users\arund\Desktop\Code\Django\portfolio-project\venv\lib\site-packages\django\contrib\auth\tokens.py", line 18, in __init__
1:53:57 PM web.1 | self.secret = self.secret or settings.SECRET_KEY
1:53:57 PM web.1 | File "C:\Users\arund\Desktop\Code\Django\portfolio-project\venv\lib\site-packages\django\conf\__init__.py", line 90, in __getattr__
1:53:57 PM web.1 | raise ImproperlyConfigured("The SECRET_KEY setting must not be empty.")
1:53:57 PM web.1 | django.core.exceptions.ImproperlyConfigured: The SECRET_KEY setting must not be empty.
[DONE] Killing all processes with signal SIGINT
1:53:57 PM web.1 Exited with exit code null
Procfile
Django doesn't magically apply environment variables to your settings. You need to do that yourself, e.g. via something like this in your settings.py:
import os
SECRET_KEY = os.getenv("SECRET_KEY", default="dev key")
In development, you can use a .env file to populate your environment, but that file should not be committed to version control. Ignore it, and use Heroku's config vars instead. They will be injected into your application's environment.
Related
I'm running my django-app-api server on docker and I'm stuck at a particular place. The server doesnt spawn due to the following error :
TypeError: init() got an unexpected keyword argument 'providing_args'
I'm getting the following error trace while running my django-api docker container using docker-compose
myproject-api-webserver | 2022-09-23 11:09:26,477 myprojectnetwork.settings INFO ALLOWED_HOSTS environment variable ignored.
myproject-api-webserver | Traceback (most recent call last):
myproject-api-webserver | File "manage.py", line 25, in <module>
myproject-api-webserver | execute_from_command_line(sys.argv)
myproject-api-webserver | File "/usr/local/lib/python3.8/site-packages/django/core/management/__init__.py", line 446, in execute_from_command_line
myproject-api-webserver | utility.execute()
myproject-api-webserver | File "/usr/local/lib/python3.8/site-packages/django/core/management/__init__.py", line 420, in execute
myproject-api-webserver | django.setup()
myproject-api-webserver | File "/usr/local/lib/python3.8/site-packages/django/__init__.py", line 24, in setup
myproject-api-webserver | apps.populate(settings.INSTALLED_APPS)
myproject-api-webserver | File "/usr/local/lib/python3.8/site-packages/django/apps/registry.py", line 91, in populate
myproject-api-webserver | app_config = AppConfig.create(entry)
myproject-api-webserver | File "/usr/local/lib/python3.8/site-packages/django/apps/config.py", line 193, in create
myproject-api-webserver | import_module(entry)
myproject-api-webserver | File "/usr/local/lib/python3.8/importlib/__init__.py", line 127, in import_module
myproject-api-webserver | return _bootstrap._gcd_import(name[level:], package, level)
myproject-api-webserver | File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
myproject-api-webserver | File "<frozen importlib._bootstrap>", line 991, in _find_and_load
myproject-api-webserver | File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
myproject-api-webserver | File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
myproject-api-webserver | File "<frozen importlib._bootstrap_external>", line 843, in exec_module
myproject-api-webserver | File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
myproject-api-webserver | File "/usr/local/lib/python3.8/site-packages/cacheops/__init__.py", line 8, in <module>
myproject-api-webserver | from .query import *
myproject-api-webserver | File "/usr/local/lib/python3.8/site-packages/cacheops/query.py", line 31, in <module>
myproject-api-webserver | from .invalidation import invalidate_obj, invalidate_dict, no_invalidation
myproject-api-webserver | File "/usr/local/lib/python3.8/site-packages/cacheops/invalidation.py", line 10, in <module>
myproject-api-webserver | from .signals import cache_invalidated
myproject-api-webserver | File "/usr/local/lib/python3.8/site-packages/cacheops/signals.py", line 3, in <module>
myproject-api-webserver | cache_read = django.dispatch.Signal(providing_args=["func", "hit"])
myproject-api-webserver | TypeError: __init__() got an unexpected keyword argument 'providing_args'
My Django version==4.1.1 & Django CacheOps==6.0.0
I've mentioned the Django & Django CacheOps since I believe this could be due to version mismatch and subsequent changes that have to made, but I do not know where to make the changes.
Also note that , the moment I upgrade to django-cacheops==6.1.0 (latest) , i get the following error which I have posted as a different question.
Django rest-api - attributeerror: 'str' object has no attribute '_meta'
It really looks like the cacheops package in version 6.0.0 still passes a keyword argument providing_args that was apparently supported up to Django 2.2 (docs), but definitely no longer in the current Django 4.1 (docs). Cacheops fixed this on 2021-02-19 (github commit), so you definitely need a version newer than that.
I have completed my Django Project using cookiecutter-django.
If I just locally run:
$ docker-compose -f local.yml build
$ docker-compose -f local.yml up
My project launches just fine in http://0.0.0.0:8000
Nonetheless, now I am trying to deploy it following this guide: https://realpython.com/development-and-deployment-of-cookiecutter-django-via-docker/
I have been able to create the local docker-machine with docker-machine create --driver virtualbox dev, activate it eval $(docker-machine env dev) and build the image, but if I run docker-compose -f local.yml up then I get the following error:
Attaching to innovacion_innsai_postgres_1, innovacion_innsai_django_1, innovacion_innsai_node_1
postgres_1 | 2020-03-12 09:14:42.686 UTC [1] LOG: listening on IPv4 address "0.0.0.0", port 5432
postgres_1 | 2020-03-12 09:14:42.686 UTC [1] LOG: listening on IPv6 address "::", port 5432
postgres_1 | 2020-03-12 09:14:42.688 UTC [1] LOG: listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
postgres_1 | 2020-03-12 09:14:42.702 UTC [21] LOG: database system was shut down at 2020-03-11 10:05:23 UTC
postgres_1 | 2020-03-12 09:14:42.732 UTC [1] LOG: database system is ready to accept connections
django_1 | PostgreSQL is available
django_1 | Traceback (most recent call last):
django_1 | File "/usr/local/lib/python3.7/site-packages/django/db/backends/utils.py", line 84, in _execute
django_1 | return self.cursor.execute(sql, params)
django_1 | psycopg2.errors.UndefinedTable: relation "innovation_sector" does not exist
django_1 | LINE 1: ...n_sector"."id", "innovation_sector"."sector" FROM "innovatio...
django_1 | ^
django_1 |
django_1 |
django_1 | The above exception was the direct cause of the following exception:
django_1 |
django_1 | Traceback (most recent call last):
django_1 | File "manage.py", line 30, in <module>
django_1 | execute_from_command_line(sys.argv)
django_1 | File "/usr/local/lib/python3.7/site-packages/django/core/management/__init__.py", line 381, in execute_from_command_line
django_1 | utility.execute()
django_1 | File "/usr/local/lib/python3.7/site-packages/django/core/management/__init__.py", line 375, in execute
django_1 | self.fetch_command(subcommand).run_from_argv(self.argv)
django_1 | File "/usr/local/lib/python3.7/site-packages/django/core/management/base.py", line 323, in run_from_argv
django_1 | self.execute(*args, **cmd_options)
django_1 | File "/usr/local/lib/python3.7/site-packages/django/core/management/base.py", line 361, in execute
django_1 | self.check()
django_1 | File "/usr/local/lib/python3.7/site-packages/django/core/management/base.py", line 390, in check
django_1 | include_deployment_checks=include_deployment_checks,
django_1 | File "/usr/local/lib/python3.7/site-packages/django/core/management/commands/migrate.py", line 65, in _run_checks
django_1 | issues.extend(super()._run_checks(**kwargs))
django_1 | File "/usr/local/lib/python3.7/site-packages/django/core/management/base.py", line 377, in _run_checks
django_1 | return checks.run_checks(**kwargs)
django_1 | File "/usr/local/lib/python3.7/site-packages/django/core/checks/registry.py", line 72, in run_checks
django_1 | new_errors = check(app_configs=app_configs)
django_1 | File "/usr/local/lib/python3.7/site-packages/django/core/checks/urls.py", line 13, in check_url_config
django_1 | return check_resolver(resolver)
django_1 | File "/usr/local/lib/python3.7/site-packages/django/core/checks/urls.py", line 23, in check_resolver
django_1 | return check_method()
django_1 | File "/usr/local/lib/python3.7/site-packages/django/urls/resolvers.py", line 399, in check
django_1 | for pattern in self.url_patterns:
django_1 | File "/usr/local/lib/python3.7/site-packages/django/utils/functional.py", line 80, in __get__
django_1 | res = instance.__dict__[self.name] = self.func(instance)
django_1 | File "/usr/local/lib/python3.7/site-packages/django/urls/resolvers.py", line 584, in url_patterns
django_1 | patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
django_1 | File "/usr/local/lib/python3.7/site-packages/django/utils/functional.py", line 80, in __get__
django_1 | res = instance.__dict__[self.name] = self.func(instance)
django_1 | File "/usr/local/lib/python3.7/site-packages/django/urls/resolvers.py", line 577, in urlconf_module
django_1 | return import_module(self.urlconf_name)
django_1 | File "/usr/local/lib/python3.7/importlib/__init__.py", line 127, in import_module
django_1 | return _bootstrap._gcd_import(name[level:], package, level)
django_1 | File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
django_1 | File "<frozen importlib._bootstrap>", line 983, in _find_and_load
django_1 | File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
django_1 | File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
django_1 | File "<frozen importlib._bootstrap_external>", line 728, in exec_module
django_1 | File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
django_1 | File "/app/config/urls.py", line 18, in <module>
django_1 | path("", include("innovacion_innsai.innovation.urls", namespace="innovation")),
django_1 | File "/usr/local/lib/python3.7/site-packages/django/urls/conf.py", line 34, in include
django_1 | urlconf_module = import_module(urlconf_module)
django_1 | File "/usr/local/lib/python3.7/importlib/__init__.py", line 127, in import_module
django_1 | return _bootstrap._gcd_import(name[level:], package, level)
django_1 | File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
django_1 | File "<frozen importlib._bootstrap>", line 983, in _find_and_load
django_1 | File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
django_1 | File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
django_1 | File "<frozen importlib._bootstrap_external>", line 728, in exec_module
django_1 | File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
django_1 | File "/app/innovacion_innsai/innovation/urls.py", line 2, in <module>
django_1 | from innovacion_innsai.innovation import views
django_1 | File "/app/innovacion_innsai/innovation/views.py", line 9, in <module>
django_1 | from .analytics import alimentacion_cases, agro_cases, turismo_cases, movilidad_cases
django_1 | File "/app/innovacion_innsai/innovation/analytics.py", line 17, in <module>
django_1 | for case in Case.objects.filter(sector__sector=sectors[0]):
django_1 | File "/usr/local/lib/python3.7/site-packages/django/db/models/query.py", line 308, in __getitem__
django_1 | qs._fetch_all()
django_1 | File "/usr/local/lib/python3.7/site-packages/django/db/models/query.py", line 1242, in _fetch_all
django_1 | self._result_cache = list(self._iterable_class(self))
django_1 | File "/usr/local/lib/python3.7/site-packages/django/db/models/query.py", line 55, in __iter__
django_1 | results = compiler.execute_sql(chunked_fetch=self.chunked_fetch, chunk_size=self.chunk_size)
django_1 | File "/usr/local/lib/python3.7/site-packages/django/db/models/sql/compiler.py", line 1133, in execute_sql
django_1 | cursor.execute(sql, params)
django_1 | File "/usr/local/lib/python3.7/site-packages/django/db/backends/utils.py", line 99, in execute
django_1 | return super().execute(sql, params)
django_1 | File "/usr/local/lib/python3.7/site-packages/django/db/backends/utils.py", line 67, in execute
django_1 | return self._execute_with_wrappers(sql, params, many=False, executor=self._execute)
django_1 | File "/usr/local/lib/python3.7/site-packages/django/db/backends/utils.py", line 76, in _execute_with_wrappers
django_1 | return executor(sql, params, many, context)
django_1 | File "/usr/local/lib/python3.7/site-packages/django/db/backends/utils.py", line 84, in _execute
django_1 | return self.cursor.execute(sql, params)
django_1 | File "/usr/local/lib/python3.7/site-packages/django/db/utils.py", line 89, in __exit__
django_1 | raise dj_exc_value.with_traceback(traceback) from exc_value
django_1 | File "/usr/local/lib/python3.7/site-packages/django/db/backends/utils.py", line 84, in _execute
django_1 | return self.cursor.execute(sql, params)
django_1 | django.db.utils.ProgrammingError: relation "innovation_sector" does not exist
django_1 | LINE 1: ...n_sector"."id", "innovation_sector"."sector" FROM "innovatio...
django_1 | ^
django_1 |
innovacion_innsai_django_1 exited with code 1
node_1 |
node_1 | > innovacion_innsai#1.1.0 dev /app
node_1 | > gulp
node_1 |
node_1 | [09:14:48] Using gulpfile /app/gulpfile.js
node_1 | [09:14:48] Starting 'default'...
node_1 | [09:14:48] Starting 'styles'...
node_1 | [09:14:48] Starting 'scripts'...
node_1 | [09:14:48] Starting 'imgCompression'...
node_1 | [09:14:48] gulp-imagemin: Minified 0 images
node_1 | [09:14:48] Finished 'imgCompression' after 34 ms
node_1 | [09:14:48] Finished 'scripts' after 128 ms
node_1 | [09:14:49] Finished 'styles' after 1.09 s
node_1 | [09:14:49] Starting 'initBrowserSync'...
node_1 | [09:14:49] Starting 'watchPaths'...
node_1 | [Browsersync] Proxying: http://django:8000
node_1 | [Browsersync] Access URLs:
node_1 | -----------------------------------
node_1 | Local: http://localhost:3000
node_1 | External: http://172.20.0.4:3000
node_1 | -----------------------------------
node_1 | UI: http://localhost:3001
node_1 | UI External: http://localhost:3001
node_1 | -----------------------------------
In case it might be relevant, if I visit the docker-machine's IP adreess and port (http://192.168.99.101:2376) before launching docker-compose build o up, the page displays "Client sent an HTTP request to an HTTPS server."
Here is my 'local.yml':
version: '3'
volumes:
local_postgres_data: {}
local_postgres_data_backups: {}
services:
django:
build:
context: .
dockerfile: ./compose/local/django/Dockerfile
image: innovacion_innsai_local_django
depends_on:
- postgres
volumes:
- .:/app
env_file:
- ./.envs/.local/.django
- ./.envs/.local/.postgres
ports:
- "8000:8000"
command: /start
postgres:
build:
context: .
dockerfile: ./compose/production/postgres/Dockerfile
image: innovacion_innsai_production_postgres
volumes:
- local_postgres_data:/var/lib/postgresql/data
- local_postgres_data_backups:/backups
env_file:
- ./.envs/.local/.postgres
node:
build:
context: .
dockerfile: ./compose/local/node/Dockerfile
image: innovacion_innsai_local_node
depends_on:
- django
volumes:
- .:/app
# http://jdlm.info/articles/2016/03/06/lessons-building-node-app-docker.html
- /app/node_modules
command: npm run dev
ports:
- "3000:3000"
# Expose browsersync UI: https://www.browsersync.io/docs/options/#option-ui
- "3001:3001"
the result of running docker-machine ls:
NAME ACTIVE DRIVER STATE URL SWARM DOCKER ERRORS
dev - virtualbox Running tcp://192.168.99.101:2376 v19.03.5
My .postgresql in the .envs/.local folder is:
# PostgreSQL
# ------------------------------------------------------------------------------
POSTGRES_HOST=postgres
POSTGRES_PORT=5432
POSTGRES_DB=innovacion_innsai
POSTGRES_USER=debug
POSTGRES_PASSWORD=debug
and my Docker file for local:
FROM python:3.7-slim-buster
ENV PYTHONUNBUFFERED 1
RUN apt-get update \
# dependencies for building Python packages
&& apt-get install -y build-essential \
# psycopg2 dependencies
&& apt-get install -y libpq-dev \
# Translations dependencies
&& apt-get install -y gettext \
# cleaning up unused files
&& apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false \
&& rm -rf /var/lib/apt/lists/*
# Requirements are installed here to ensure they will be cached.
COPY ./requirements /requirements
RUN pip install -r /requirements/local.txt
COPY ./compose/production/django/entrypoint /entrypoint
RUN sed -i 's/\r$//g' /entrypoint
RUN chmod +x /entrypoint
COPY ./compose/local/django/start /start
RUN sed -i 's/\r$//g' /start
RUN chmod +x /start
WORKDIR /app
ENTRYPOINT ["/entrypoint"]
Please, I am quite new with Django and Docker so excuse me if I did not explain myself properly. Also, please let me know if you would need any other script or information in order to take a proper look at the problem!
I dont know if you already figured this out and I don't know if I'm right but give this a try:
Instead of:
docker-compose -f local.yml up
Try:
docker-compose -f production.yml up
When you're deploying to production you should build and bring up the site with the production file not the local file.
Hi I am following the django tutorial (Quickstart: Compose and Django) of .. and I have this error:
SyntaxError: Generator expression must be parenthesized
traceback
root#localhost:~# docker-compose up
Starting root_db_1 ... done
Starting root_web_1 ... done
Attaching to root_db_1, root_web_1
db_1 | 2018-09-09 00:09:10.440 UTC [1] LOG: listening on IPv4 address "0.0.0.0", port 5432
db_1 | 2018-09-09 00:09:10.440 UTC [1] LOG: listening on IPv6 address "::", port 5432
db_1 | 2018-09-09 00:09:10.442 UTC [1] LOG: listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
db_1 | 2018-09-09 00:09:10.481 UTC [21] LOG: database system was interrupted; last known up at 2018-09-09 00:06:36 UTC
db_1 | 2018-09-09 00:09:10.597 UTC [21] LOG: database system was not properly shut down; automatic recovery in progress
db_1 | 2018-09-09 00:09:10.599 UTC [21] LOG: redo starts at 0/1633C88
db_1 | 2018-09-09 00:09:10.599 UTC [21] LOG: invalid record length at 0/1633CC0: wanted 24, got 0
db_1 | 2018-09-09 00:09:10.599 UTC [21] LOG: redo done at 0/1633C88
db_1 | 2018-09-09 00:09:10.632 UTC [1] LOG: database system is ready to accept connections
web_1 | Unhandled exception in thread started by <function check_errors.<locals>.wrapper at 0x7f652d99d510>
web_1 | Traceback (most recent call last):
web_1 | File "/usr/local/lib/python3.7/site-packages/django/utils/autoreload.py", line 228, in wrapper
web_1 | fn(*args, **kwargs)
web_1 | File "/usr/local/lib/python3.7/site-packages/django/core/management/commands/runserver.py", line 116, in inner_run
web_1 | autoreload.raise_last_exception()
web_1 | File "/usr/local/lib/python3.7/site-packages/django/utils/autoreload.py", line 251, in raise_last_exception
web_1 | six.reraise(*_exception)
web_1 | File "/usr/local/lib/python3.7/site-packages/django/utils/six.py", line 685, in reraise
web_1 | raise value.with_traceback(tb)
web_1 | File "/usr/local/lib/python3.7/site-packages/django/utils/autoreload.py", line 228, in wrapper
web_1 | fn(*args, **kwargs)
web_1 | File "/usr/local/lib/python3.7/site-packages/django/__init__.py", line 27, in setup
web_1 | apps.populate(settings.INSTALLED_APPS)
web_1 | File "/usr/local/lib/python3.7/site-packages/django/apps/registry.py", line 85, in populate
web_1 | app_config = AppConfig.create(entry)
web_1 | File "/usr/local/lib/python3.7/site-packages/django/apps/config.py", line 94, in create
web_1 | module = import_module(entry)
web_1 | File "/usr/local/lib/python3.7/importlib/__init__.py", line 127, in import_module
web_1 | return _bootstrap._gcd_import(name[level:], package, level)
web_1 | File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
web_1 | File "<frozen importlib._bootstrap>", line 983, in _find_and_load
web_1 | File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
web_1 | File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
web_1 | File "<frozen importlib._bootstrap_external>", line 728, in exec_module
web_1 | File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
web_1 | File "/usr/local/lib/python3.7/site-packages/django/contrib/admin/__init__.py", line 4, in <module>
web_1 | from django.contrib.admin.filters import (
web_1 | File "/usr/local/lib/python3.7/site-packages/django/contrib/admin/filters.py", line 10, in <module>
web_1 | from django.contrib.admin.options import IncorrectLookupParameters
web_1 | File "/usr/local/lib/python3.7/site-packages/django/contrib/admin/options.py", line 13, in <module>
web_1 | from django.contrib.admin import helpers, widgets
web_1 | File "/usr/local/lib/python3.7/site-packages/django/contrib/admin/widgets.py", line 152
web_1 | '%s=%s' % (k, v) for k, v in params.items(),
web_1 | ^
web_1 | SyntaxError: Generator expression must be parenthesized
^CGracefully stopping... (press Ctrl+C again to force)
Stopping root_web_1 ...
Stopping root_db_1 ...
Killing root_web_1 ... done
Killing root_db_1 ... done
Dockerfile
FROM python:3
ENV PYTHONUNBUFFERED 1
RUN mkdir /code
WORKDIR /code
ADD requirements.txt /code/
RUN pip install -r requirements.txt
ADD . /code/
docker-compose.yml
version: '3'
services:
db:
image: postgres
web:
build: .
command: python3 manage.py runserver 0.0.0.0:8000
volumes:
- .:/code
ports:
- "8000:8000"
depends_on:
- db
First sudo service docker restart
And in your Dockerfile
FROM python:3.6
then sudo docker-compose up --build
or
sudo docker-compose run web python manage.py migrate and sudo docker-compose up --build
Update your Django version in requirements.txt file from Django>=1.8,<2.0 to Django==2.1.1
Run your image with rebuild by "docker-compose up --build" it will solve your problem.
I'm following the getting started with Python tutorial at Heroku, and I'm stuck at the "Run the app locally" step. I'm on a Windows 7 machine, and I've managed all previous steps successfully. The following code was run in the Git Bash provided by the toolbelt inside a virtualenv as described. The error appears below.
The ProcFile says (as per the instructions)
web: python manage.py runserver 0.0.0.0:$PORT
and the command foreman start web fails with the error depicted below.
If I just enter python manage.py runserver 0.0.0.0:5000 into the prompt, the server starts right up and I can visit the app. Maybe this is sufficient to develop locally, but maybe not, so if anyone can shed some light on what's going on, I'd be grateful. Thank you.
PS: I should also emphasize that as per this step gunicorn was worked out of the requirements, so unlike many questions similar to this, gunicorn is not supposed to be part of the picture.
(venv)John#JOHN-PC ~/python-getting-started (master)
$ foreman start web
16:06:13 web.1 | started with pid 24536
16:06:13 web.1 | Traceback (most recent call last):
16:06:13 web.1 | File "manage.py", line 10, in <module>
16:06:13 web.1 | execute_from_command_line(sys.argv)
16:06:13 web.1 | File "c:\Users\John\python-getting-started\venv\lib\site-packages\django\core\management\__init__.py", line 399, in execute_from_command_line
16:06:13 web.1 | utility.execute()
16:06:13 web.1 | File "c:\Users\John\python-getting-started\venv\lib\site-packages\django\core\management\__init__.py", line 392, in execute
16:06:13 web.1 | self.fetch_command(subcommand).run_from_argv(self.argv)
16:06:13 web.1 | File "c:\Users\John\python-getting-started\venv\lib\site-packages\django\core\management\base.py", line 242, in run_from_argv
16:06:13 web.1 | self.execute(*args, **options.__dict__)
16:06:13 web.1 | File "c:\Users\John\python-getting-started\venv\lib\site-packages\django\core\management\base.py", line 280, in execute
16:06:13 web.1 | translation.activate('en-us')
16:06:13 web.1 | File "c:\Users\John\python-getting-started\venv\lib\site-packages\django\utils\translation\__init__.py", line 130, in activate
16:06:13 web.1 | return _trans.activate(language)
16:06:13 web.1 | File "c:\Users\John\python-getting-started\venv\lib\site-packages\django\utils\translation\trans_real.py", line 188, in activate
16:06:13 web.1 | _active.value = translation(language)
16:06:13 web.1 | File "c:\Users\John\python-getting-started\venv\lib\site-packages\django\utils\translation\trans_real.py", line 177, in translation
16:06:13 web.1 | default_translation = _fetch(settings.LANGUAGE_CODE)
16:06:13 web.1 | File "c:\Users\John\python-getting-started\venv\lib\site-packages\django\utils\translation\trans_real.py", line 159, in _fetch
16:06:13 web.1 | app = import_module(appname)
16:06:13 web.1 | exited with code 1
16:06:13 system | sending SIGKILL to all processes
16:06:13 | File "c:\Users\John\python-getting-started\venv\lib\site -packages\django\utils\importlib.py", line 40, in import_module
I'm following Getting Started with Django on Heroku tutorial
When I'm trying to run Django app on the Gunicorn using Foreman, i get next error traceback:
09:23:33 web.1 | started with pid 7012
09:23:34 web.1 | 2013-05-06 09:23:34 [7012] [INFO] Starting gunicorn 0.17.2
09:23:34 web.1 | 2013-05-06 09:23:34 [7012] [INFO] Listening at: `http://0.0.0.0:5000` (7012)
09:23:34 web.1 | 2013-05-06 09:23:34 [7012] [INFO] Using worker: sync
09:23:34 web.1 | 2013-05-06 09:23:34 [7015] [INFO] Booting worker with pid: 7015
09:23:34 web.1 | 2013-05-06 09:23:34 [7015] [ERROR] Exception in worker process:
09:23:34 web.1 | Traceback (most recent call last):
09:23:34 web.1 | File "/usr/local/lib/python2.7/site-packages/gunicorn/arbiter.py", line 485, in spawn_worker
09:23:34 web.1 | worker.init_process()
09:23:34 web.1 | File "/usr/local/lib/python2.7/site-packages/gunicorn/workers/base.py", line 100, in init_process
09:23:34 web.1 | self.wsgi = self.app.wsgi()
09:23:34 web.1 | File "/usr/local/lib/python2.7/site-packages/gunicorn/app/base.py", line 103, in wsgi
09:23:34 web.1 | self.callable = self.load()
09:23:34 web.1 | File "/usr/local/lib/python2.7/site-packages/gunicorn/app/wsgiapp.py", line 25, in load
09:23:34 web.1 | return util.import_app(self.app_uri)
09:23:34 web.1 | File "/usr/local/lib/python2.7/site-packages/gunicorn/util.py", line 372, in import_app
09:23:34 web.1 | __import__(module)
09:23:34 web.1 | File "/Users/cosmicMan66/DjangoDev/hepcat_server/hepcat_server/wsgi.py", line 27, in <module>
09:23:34 web.1 | from django.core.wsgi import get_wsgi_application
09:23:34 web.1 | ImportError: No module named django.core.wsgi
09:23:34 web.1 | Traceback (most recent call last):
09:23:34 web.1 | File "/usr/local/lib/python2.7/site-packages/gunicorn/arbiter.py", line 485, in spawn_worker
09:23:34 web.1 | worker.init_process()
09:23:34 web.1 | File "/usr/local/lib/python2.7/site-packages/gunicorn/workers/base.py", line 100, in init_process
09:23:34 web.1 | self.wsgi = self.app.wsgi()
09:23:34 web.1 | File "/usr/local/lib/python2.7/site-packages/gunicorn/app/base.py", line 103, in wsgi
09:23:34 web.1 | self.callable = self.load()
09:23:34 web.1 | File "/usr/local/lib/python2.7/site-packages/gunicorn/app/wsgiapp.py", line 25, in load
09:23:34 web.1 | return util.import_app(self.app_uri)
09:23:34 web.1 | File "/usr/local/lib/python2.7/site-packages/gunicorn/util.py", line 372, in import_app
09:23:34 web.1 | __import__(module)
09:23:34 web.1 | File "/Users/cosmicMan66/DjangoDev/hepcat_server/hepcat_server/wsgi.py", line 27, in <module>
09:23:34 web.1 | from django.core.wsgi import get_wsgi_application
09:23:34 web.1 | ImportError: No module named django.core.wsgi
09:23:34 web.1 | 2013-05-06 09:23:34 [7015] [INFO] Worker exiting (pid: 7015)
09:23:35 web.1 | 2013-05-06 09:23:35 [7012] [INFO] Shutting down: Master
09:23:35 web.1 | 2013-05-06 09:23:35 [7012] [INFO] Reason: Worker failed to boot.
09:23:35 web.1 | exited with code 3
09:23:35 system | sending SIGTERM to all processes
SIGTERM received
Procfile is located in the root directory of a project and contains:
web: gunicorn hepcat_server.wsgi
settings.py is located in hepcat_server directory
when I use $ python manage.py run_gunicorn
gunicorn starts successfully and I see default Django page
I had the same issue while following the Heroku setup page you were using. I found a solution on this page. I've copied it here for posterity:
In the root directory of your django project, create the Procfile file.
then write this on it web: sh -c "cd djangoproject && gunicorn
djangoproject.wsgi". then create another file called .env in the same
location, write DJANGO_SETTINGS_MODULE=djangoproject.settings into it,
this will help you setting the required env variable that cannot be
set in djangoproject.wsgi module. run foreman start in order to test.
What this does should be self explanatory giving the issue below.
When you deploy, after creating your application in heroku, set the
env variable with this command heroku config:set
DJANGO_SETTINGS_MODULE=djangoproject.settings, this is because the
deployment fails before the file djangoproject/djangoproject/wsgi.py
is run.
remember to replace "djangoproject" with the name of your django project.