REST API - Serialized models do not take hostname from the production server - Django REST Framework

2

I am exposing an application (at the moment it is only your user scheme) with Django Rest Framework, and it happens to me that every model that I have serialized, in the url attribute, I have is the address of the localhost of my development machine and I do not take the hostname of my production machine which is in amazon EC2.

This picture can be detailed

How can I make the hostname of the machine where I am, in this case my production server that is an Amazon EC2 instance?

These are my serialized models in userprofiles/serializers.py

from django.contrib.auth.models import Group
from .models import User, PlayerProfile, CoachProfile, ViewerProfile

from rest_framework import serializers


# Serializers define the API representation
# Exponse the model and their fields
class UserSerializer(serializers.HyperlinkedModelSerializer):
    class Meta:
        model = User
        fields = ('url','id', 'username', 'password','first_name','last_name','email','is_active',
                  'is_staff','is_superuser','last_login','date_joined','is_player','is_coach',
                  'is_viewer','photo',)

class GroupSerializer(serializers.HyperlinkedModelSerializer):
    class Meta:
        model = Group
        fields = ('url', 'name')


class PlayerProfileSerializer(serializers.HyperlinkedModelSerializer):
    class Meta:
        model = PlayerProfile
        fields = ('url', 'user','full_name','position',)

class CoachProfileSerializer(serializers.HyperlinkedModelSerializer):
    class Meta:
        model = CoachProfile
        fields = ('url', 'user','full_name',)

class ViewerProfileSerializer(serializers.HyperlinkedModelSerializer):
    class Meta:
        model = ViewerProfile
        fields = ('url', 'user','full_name','specialty')

This is my global urls.py file (not the userprofiles application that contains the serialized models)

from django.conf.urls import url, include
from django.contrib import admin

from .views import home, home_files

from rest_framework import routers
from userprofiles import views

# Router provide an easy way of automatically determining the URL conf
router = routers.DefaultRouter()
router.register(r'users', views.UserViewSet)
router.register(r'groups', views.GroupViewSet)
router.register(r'players', views.PlayerProfileViewSet)
router.register(r'coachs', views.CoachProfileViewSet)
router.register(r'views', views.ViewerProfileViewSet)


urlpatterns = [
    url(r'^admin/', admin.site.urls),
    url(r'^$', home, name='home'),

    url(r'^(?P<filename>(robots.txt)|(humans.txt))$',
        home_files, name='home-files'),

    # Wire up our API using automatic URL routing.
    url(r'^api/v1/', include(router.urls)),

    # If you're intending to use the browsable API you'll probably also want to add REST framework's
    # login and logout views.
    url(r'^api-auth/', include('rest_framework.urls', namespace='rest_framework'))
]

And this is my userprofiles/views.py file where the serialized models are exposed

from django.shortcuts import render
from django.contrib.auth.models import Group
from .models import User, PlayerProfile, CoachProfile, ViewerProfile

from rest_framework import viewsets
from .serializers import UserSerializer, GroupSerializer, PlayerProfileSerializer, CoachProfileSerializer, ViewerProfileSerializer

# Create your views here.

# Viewsets define the behavior of the view
class UserViewSet(viewsets.ModelViewSet):
    """
    API endpoint that allows users to be viewed or edited.
    """
    queryset = User.objects.all().order_by('-date_joined')
    serializer_class = UserSerializer

class GroupViewSet(viewsets.ModelViewSet):
    """
    API endpoint that allows groups to be viewed or edited.
    """
    queryset = Group.objects.all()
    serializer_class = GroupSerializer

class PlayerProfileViewSet(viewsets.ModelViewSet):
    """
    API endpoint that allows players to be viewed or edited.
    """
    queryset = PlayerProfile.objects.all()
    serializer_class = PlayerProfileSerializer

class CoachProfileViewSet(viewsets.ModelViewSet):
    """
    API endpoint that allows coachs to be viewed or edited.
    """
    queryset = CoachProfile.objects.all()
    serializer_class = CoachProfileSerializer

class ViewerProfileViewSet(viewsets.ModelViewSet):
    """
    API endpoint that allows viewers to be viewed or edited.
    """
    queryset = ViewerProfile.objects.all()
    serializer_class = ViewerProfileSerializer
    
asked by bgarcial 20.02.2016 в 19:15
source

0 answers