C
C
ckatala2019-06-15 13:41:20
Django
ckatala, 2019-06-15 13:41:20

Django request.build_absolute_uri?

Why does request.build_absolute_uri return localhost:8000 but not the domain name?
Jungi server + nginx proxy started

location / {
  proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  proxy_set_header Host $http_host;
  proxy_redirect off;
  proxy_pass http://localhost:8000/;
}

In the model
return request.build_absolute_uri(profile_picture_url)

returns http:// localhost:8000/ m/avatar.png
I need http:// domain/ m/avatar.png

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
neatsoft, 2019-06-15
@neatsoft

1. В settings.py нужно добавить USE_X_FORWARDED_HOST == True
2. В конфигурации Nginx установить хэдер X-Forwarded-Host
Документация: Django documentation > Settings > USE_X_FORWARDED_HOST
Функция, которая возвращает имя хоста: request.py:_get_raw_host()

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question