Home>

There was such a problem, trying to start the site through the Dokk Conise, it gives such a mistake. An error occurs when entering the lokalchost, an attempt to make migration and create a superuser. I tried to clean the containers, volumes, images -the result did not give. Below I attach the error itself, the docks of the computer and the database settings.

TracEBack (MOST Recent Call Last):
Web_1 | File "/usr/local/lib/python3.8/site-packages/gunicorn/workers/sync.py", line 134, in handle
Web_1 | Self.Hlandle_Request (Listener, Req, Client, ADDR)
Web_1 | File "/usr/local/lib/python3.8/site-packages/gunicorn/workers/sync.py", line 175, in handle_request
Web_1 | Respiter= Self.wsgi (Environ, Resp.Start_Response)
Web_1 | File "/usr/local/lib/python3.8/site-packages/django/core/handlers/wsgi.py", line 141, in __call__
Web_1 | Response= Self.Get_Response (Request)
Web_1 | File "/usr/local/lib/python3.8/site-packages/django/core/handlers/base.py", Line 75, in Get_Response
Web_1 | Response= Self._midDleWare_CHAIN ​​(Request)
Web_1 | File "/usr/local/lib/python3.8/site-packages/django/core/handlers/exception.py", Line 36, in Inner
Web_1 | Response= Response_For_Exception (Request, Exc)
Web_1 | File "/usr/local/lib/python3.8/site-packages/django/core/handlers/exception.py", Line 90, in Response_For_Exception
Web_1 | Response= Handle_uncaught_Exception (Request, Get_Resolver (get_urlconf ()), sys.exc_info ())
Web_1 | File "/usr/local/lib/python3.8/site-packages/django/core/handlers/exception.py", line 129, in handle_uncaught_exception
Web_1 | Return Callback (Request, ** Param_DICT)
Web_1 | File "/code/foodgram/views.py", Line 10, in Server_error
Web_1 | Return Render (Request, 'Misc /500.html', Status= 500)
Web_1 | File "/usr/local/lib/python3.8/site-packages/django/shortcuts.py", Line 36, in Render
Web_1 | Content= Loader.Render_Name_String (Template_Name, Context, Request, using= Using)
Web_1 | File "/usr/local/lib/python3.8/site-packages/django/template/loader.py", Line 62, in Render_To_String
Web_1 | Return Template.Render (Context, Request)
Web_1 | File "/usr/local/lib/python3.8/site-packages/django/template/backenDs/django.py", line 61, in render
Web_1 | Return Self.Template.Render (Context)
Web_1 | File "/usr/local/lib/python3.8/site-packages/django/template/base.py", line 171, in render
Web_1 | Return Self._render (Context)
Web_1 | File "/usr/local/lib/python3.8/site-packages/django/template/base.py", line 163, in _render
Web_1 | Return Self.Nodelist.Render (Context)
Web_1 | File "/usr/local/lib/python3.8/site-packages/django/template/base.py", line 937, in render
Web_1 | Bit= Node.Render_annotated (Context)
Web_1 | File "/usr/local/lib/python3.8/site-packages/django/template/base.py", Line 904, in Render_annotated
Web_1 | Return Self.render (Context)
Web_1 | File "/usr/local/lib/python3.8/site-packages/django/template/loader_tags.py", Line 150, in Render
Web_1 | Return Compiled_Parent._Render (Context)
Web_1 | File "/usr/local/lib/python3.8/site-packages/django/template/base.py", line 163, in _render
Web_1 | Return Self.Nodelist.Render (Context)
Web_1 | File "/usr/local/lib/python3.8/site-packages/django/template/base.py", line 937, in render
Web_1 | Bit= Node.Render_annotated (Context)
Web_1 | File "/usr/local/lib/python3.8/site-packages/django/template/base.py", Line 904, in Render_annotated
Web_1 | Return Self.render (Context)
Web_1 | File "/usr/local/lib/python3.8/site-packages/django/template/loader_tags.py", Line 188, In Render
Web_1 | RETURN TEMPLATE.RENDER (CONTEXT)
Web_1 | File "/usr/local/lib/python3.8/site-packages/django/template/base.py", line 173, in render
Web_1 | Return Self._render (Context)Web_1 | File "/usr/local/lib/python3.8/site-packages/django/template/base.py", line 163, in _renderweb_1 | Return Self.Nodelist.Render (Context)
Web_1 | File "/usr/local/lib/python3.8/site-packages/django/template/base.py", line 937, in render
Web_1 | Bit= Node.Render_annotated (Context)
Web_1 | File "/usr/local/lib/python3.8/site-packages/django/template/base.py", Line 904, in Render_annotated
Web_1 | Return Self.render (Context)
Web_1 | File "/usr/local/lib/python3.8/site-packages/django/template/defaultTags.py", Line 302, in Render
Web_1 | Match= CONDITION.EVAL (CONTEXT)
Web_1 | File "/usr/local/lib/python3.8/site-packages/django/template/DefaultTags.py", line 876, in eval
Web_1 | Return Self.Value.Resolve (CONTEXT, IGNORE_FAILURES= TRUE)
Web_1 | File "/usr/local/lib/python3.8/site-packages/django/template/base.py", Line 671, in resolve
Web_1 | OBJ= Self.Var.Resolve (Context)
Web_1 | File "/usr/local/lib/python3.8/site-packages/django/template/base.py", Line 796, in resolve
Web_1 | Value= Self._resolve_LookUp (Context)
Web_1 | File "/usr/local/lib/python3.8/site-packages/django/template/base.py", line 829, in _resolve_lookup
Web_1 | CURRENT= CURRENT [BIT]
Web_1 | File "/usr/local/lib/python3.8/site-packages/django/utils/functional.py", Line 256, in Inner
Web_1 | Self._setup ()
Web_1 | File "/usr/local/lib/python3.8/site-packages/django/utils/functional.py", Line 392, in _setup
Web_1 | self._Wrapped= Self._setupfunc ()
Web_1 | File "/usr/local/lib/python3.8/site-packages/django/contrib/auth/middleware.py", Line 24, In <
Lambda >
Web_1 | Request.user= SimpleLazyObject (Lambda: Get_user (Request))
Web_1 | File "/usr/local/lib/python3.8/site-packages/django/contrib/auth/middleware.py", line 12, in get_user
Web_1 | Request._CACHED_USER= auth.get_user (Request)
Web_1 | File "/usr/local/lib/python3.8/site-packages/django/contrib/auth/__init__.py", line 182, in get_user
Web_1 | User_ID= _GET_USER_SESSION_KEY (Request)
Web_1 | File "/usr/local/lib/python3.8/site-packages/django/contrib/auth/__init__.py", line 59, in _get_user_session_key
Web_1 | Return Get_user_Model () ._ Meta.pk.to_python (Request.Session [Session_Key])
Web_1 | File "/usr/local/lib/python3.8/site-packages/django/contrib/sessions/backends/base.py", line 54, in __getitem__
Web_1 | RETURN SELF._SESSION [KEY]
Web_1 | File "/usr/local/lib/python3.8/site-packages/django/contrib/sessions/backends/base.py", Line 194, in _get_session
Web_1 | Self._session_cache= Self.Load ()
Web_1 | File "/usr/local/lib/python3.8/site-packages/django/contrib/sessions/backends/db.py", line 43, in load
Web_1 | S= Self._Get_Session_From_DB ()
Web_1 | File "/usr/local/lib/python3.8/site-packages/django/contrib/sessions/backends/db.py", line 32, in _get_session_from_db
Web_1 | Return Self.Model.Objects.get (
Web_1 | File "/usr/local/lib/python3.8/site-packages/django/db/models/manager.py", line 82, in manager_method
Web_1 | Return Getattr (Self.get_Queryset (), Name) (* Args, ** kwargs)
Web_1 | File "/usr/local/lib/python3.8/site-packages/django/db/models/query.py", Line 402, in Get
Web_1 | Num= Len (Clone)
Web_1 | File "/usr/local/lib/python3.8/site-packages/django/db/models/query.py", line 256, in __len__
Web_1 | Self._Fetch_all ()
Web_1 | File "/usr/local/lib/python3.8/site-packages/django/db/models/query.py", line 1242, in _fetch_all
Web_1 | Self._result_cache= List (self._iterable_class (SELF))
Web_1 | File "/usr/local/lib/python3.8/site-packages/django/db/models/query.py", line 55, in __iter__
Web_1 | Results= Compiler.Execute_SQL (chunked_fetch= self.chunked_fetch, chunk_size= self.chunk_size)
Web_1 | File "/usr/local/lib/python3.8/site-packages/django/db/models/sql/compiler.py", line 1095, in execute_sql
Web_1 | CURSOR= Self.connection.cursor ()
Web_1 | File "/usr/local/lib/python3.8/site-packages/django/db/backends/base/base.py", line 256, in cursor
Web_1 | Return Self._cursor ()Web_1 | File "/usr/local/lib/python3.8/site-packages/django/db/backends/base/base.py", line 233, in _cursorweb_1 | Self.ensure_Connection ()
Web_1 | File "/usr/local/lib/python3.8/site-packages/django/db/backends/base/base.py", Line 217, in Ensure_Connection
Web_1 | self.connect ()
Web_1 | File "/usr/local/lib/python3.8/site-packages/django/db/utils.py", Line 89, in __exit__
Web_1 | RAISE DJ_EXC_VALUE.WITH_TRACEBACK (TRACEBACK) from EXC_VALUE
Web_1 | File "/usr/local/lib/python3.8/site-packages/django/db/backends/base/base.py", Line 217, in Ensure_Connection
Web_1 | self.connect ()
Web_1 | File "/usr/local/lib/python3.8/site-packages/django/db/backends/base/base.py", Line 195, in Connect
Web_1 | self.connection= self.get_new_connection (CONN_PARAMS)
Web_1 | File "/usr/local/lib/python3.8/site-packages/django/db/backends/postgresql/base.py", Line 178, in Get_new_Connection
Web_1 | Connection= Database.Connect (** Conn_params)
Web_1 | File "/usr/local/lib/python3.8/site-packages/psycopg2/__init__.py", line 127, in connect
Web_1 | Conn= _Connect (DSN, Connection_Factory= Connection_Factory, ** kwasync)
Web_1 | django.db.utils.operationalerror: COULD NOT CONNECT TO SERVER: Connection refused
Web_1 | IS The Server Running On Host "Localhost" (127.0.0.1) and accepting
Web_1 | TCP /IP Connections on port 5432?
Web_1 | COULD NOT CONNECT TO SERVER: CANNOT ASSIGN REQUESTED ADDRESS
Web_1 | IS The Server Running On Host "Localhost" (:: 1) and accepting
Web_1 | TCP /IP Connections on port 5432?

docker-compose.yaml

Version: '3.8'
Volumes:
  Postgres_Data:
  static_volume:
  Media:
Services:
  DB:
    Image: Postgres: 12.0-Alpine
    Volumes:
      -Postgres_data: /var /lib /postgreSQL /DATA /
    ENV_FILE:
      -./.env.
  Web:
    Image: BDCRY /FOODGRAM: LATEST
    Restart: Always
    Volumes:
      -Static_VOLUME: /Code /Static /
      -Media: /Code /Media
    DEPENDS_ON:
      -DB.
    ENV_FILE:
      -./.env
  nginx:
    Image: Nginx: 1.19.0
    Volumes:
      -Media: /Code /Media
      -Static_VOLUME: /Code /Static /
      -./default.conf :/etc/nginx/conf.d/default.conf.
    Ports:
      -"80:80"
    DEPENDS_ON:
      -Web.

settings.py

databases= {
    'Default': {
        'Engine': 'django.db.backends.postgreSQL',
        'Name': 'postgres',
        'User': 'Postgres',
        'Password': '0906',
        'Host': 'Localhost',
        'Port': '5432',
    }
}

In settings.py host must be DB (i.e., as a service name in docker-compose.yml), not localhost.

Roman Konoval2021-08-27 22:31:08

Unfortunately, it did not work: (changed the name on DB -the same error.

bdc12021-08-27 22:31:08

Did you watch the login logs, does it work at all?

Exploding Kitten2021-08-27 22:31:08

The second, a fairly frequent problem, this is that the postgres has not yet had time to start when the dependent container is already trying to join it. Read docs.docker.com/compose/startup-order.

Roman Konoval2021-08-27 22:31:08

And update the question if you changed Localhost. With Localhost, it will not be exactly.

Roman Konoval2021-08-27 22:31:08