小编Bra*_*low的帖子

我如何配置django rest框架分页URL

当我在django rest框架中获得一个对象时,url总是绝对地使用localhost,但是在生产中我通过nginx上的代理,有没有办法在设置中设置这个url

count: 11
next: "http://localhost:8000/api/accounts/?ordering=-date_registered&page=2"
previous: null
Run Code Online (Sandbox Code Playgroud)

我需要它

count: 11
next: "http:/example.com/api/accounts/?ordering=-date_registered&page=2"
previous: null
Run Code Online (Sandbox Code Playgroud)

----------编辑--------------------------

请看我完整的nginx配置

server {
    listen 80;
    server_name 123.123.123.123;
    root            /home/admin/www/site-web/dist;
    index           index.html;
    charset         utf-8;


    location /static/ {
        alias /home/admin/www/site/static/;
    }

    location /media/  {
        alias /home/admin/www/site/media/;
    }

    location /nginx_status/ {
        # Turn on nginx stats
        stub_status on;
        # I do not need logs for stats
        access_log  off;
        # Security: Only allow access from 192.168.1.100 IP #
        # allow 192.168.1.100;
        # Send rest of the world …
Run Code Online (Sandbox Code Playgroud)

django django-rest-framework

10
推荐指数
2
解决办法
2408
查看次数

标签 统计

django ×1

django-rest-framework ×1