Re: API REST - Url's Serialized models don't work with the hostname of my production server - Django Rest Framework

2016-02-23 Thread Bernardo Garcia
Hi James. 
Thanks for your attention and the stackoverflow reference

I try setup the headers in my nginx configuration file but I don't get 
success

My /etc/nginx/sites-enabled/myproject file I had so:

server {
server_name yourdomainorip.com;
access_log off;
location / {
proxy_pass http://127.0.0.1:8000;
proxy_set_header X-Forwarded-Host $server_name
proxy_set_header X-Real-IP $remote_addr;
add_header P3P 'CP="ALL DSP COR PSAa PSDa OUR NOR ONL UNI COM 
NAV"';
}
}


According to the 
reference 
http://stackoverflow.com/questions/19669376/django-rest-framework-absolute-urls-with-nginx-always-return-127-0-0-1
 
my /etc/nginx/sites-enabled/myproject file I stayed so:

server {
server_name yourdomainorip.com;
access_log off;
location / {
proxy_pass http://127.0.0.1:8000;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
add_header P3P 'CP="ALL DSP COR PSAa PSDa OUR NOR ONL UNI COM 
NAV"';
}
}

But, the result was a bad request (400) how to you can see here 
http://ec2-52-90-253-22.compute-1.amazonaws.com/ 

What is the order in which I should setup the headers?
Thanks
On Tuesday, February 23, 2016 at 4:51:16 PM UTC-5, James Schneider wrote:
>
>
>
> On Tue, Feb 23, 2016 at 6:03 AM, Bernardo Garcia  > wrote:
>
>> Hi everyone Djangonauts
>> :)
>>
>> Currently I am exposing a Django application (for the momento is just 
>> thier users schema) with Django Rest Framework and happen that each 
>> serialized model, in the url attribute, I have is the localhost machine 
>> address development and don't take the hostname of my production server 
>> machine which is located in amazon like as EC2 instance
>>
>>
>> In this picture can detailed it.
>>
>
> Nginx is proxying the end-users' request to http://127.0.0.1:8000, which 
> is where Gunicorn is running. Gunicorn has no idea that there is a proxy in 
> front of it, so it assumes that the request is being sent by the server 
> itself, to the server itself. Gunicorn then passes along the Host header to 
> Django/DRF, which in turn uses it to generate the URL's that you are 
> getting.
>
> You need to tell Nginx to send the correct headers to indicate to Gunicorn 
> that the connection is being proxied, and the correct address to use. See 
> this SO: 
>
>
> http://stackoverflow.com/questions/19669376/django-rest-framework-absolute-urls-with-nginx-always-return-127-0-0-1
>
> -James
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/740b268b-df39-4b2d-bd81-33217a154de0%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: API REST - Url's Serialized models don't work with the hostname of my production server - Django Rest Framework

2016-02-23 Thread James Schneider
On Tue, Feb 23, 2016 at 6:03 AM, Bernardo Garcia  wrote:

> Hi everyone Djangonauts
> :)
>
> Currently I am exposing a Django application (for the momento is just
> thier users schema) with Django Rest Framework and happen that each
> serialized model, in the url attribute, I have is the localhost machine
> address development and don't take the hostname of my production server
> machine which is located in amazon like as EC2 instance
>
>
> In this picture can detailed it.
>

Nginx is proxying the end-users' request to http://127.0.0.1:8000, which is
where Gunicorn is running. Gunicorn has no idea that there is a proxy in
front of it, so it assumes that the request is being sent by the server
itself, to the server itself. Gunicorn then passes along the Host header to
Django/DRF, which in turn uses it to generate the URL's that you are
getting.

You need to tell Nginx to send the correct headers to indicate to Gunicorn
that the connection is being proxied, and the correct address to use. See
this SO:

http://stackoverflow.com/questions/19669376/django-rest-framework-absolute-urls-with-nginx-always-return-127-0-0-1

-James

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CA%2Be%2BciUuy1nKmLqgT%2BJFPsRDDkcxkaxA%3DU46jZfHcD5Xnawg2w%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: API REST - Url's Serialized models don't work with the hostname of my production server - Django Rest Framework

2016-02-23 Thread Bernardo Garcia
Felipe, give me a couple of minutes and I tell to you, but If you see my 
first post in this thread, the api links is related with the serializers.py 
file, in the urls.py files the router.register sentence and the views.py 
the ViewSet class

In this post   is detailed 
... 
http://stackoverflow.com/questions/35565749/api-rest-urls-serialized-models-dont-work-with-the-hostname-of-my-production
 
and in the djangorestframework tutorial explain how to 
doing http://www.django-rest-framework.org/tutorial/quickstart/

On Tuesday, February 23, 2016 at 12:39:49 PM UTC-5, Fellipe Henrique wrote:
>
> Sorry to reply your post, but.. how do you show all api link? there's any 
> settings for these? I asking because, when I try on my api, show me 404 
> page...
>
>
>
>
> T.·.F.·.A.·. S+F
> *Fellipe Henrique P. Soares*
>
> e-mail: > echo "lkrrovknFmsgor4ius" | perl -pe \ 
> 's/(.)/chr(ord($1)-2*3)/ge'
> *Fedora Ambassador: https://fedoraproject.org/wiki/User:Fellipeh 
> *
> *Blog: *http:www.fellipeh.eti.br
> *GitHub: https://github.com/fellipeh *
> *Twitter: @fh_bash*
>
> On Tue, Feb 23, 2016 at 12:42 PM, Bernardo Garcia  > wrote:
>
> Avraham, so yes, efectively ...
>
> This is my gunicorn_config.py
>
> command = '/opt/uleague/bin/gunicorn'
> pythonpath = '/opt/uleague/pickapp'
> bind = '127.0.0.1:8000'
> workers = 3
>
>
> I will should in the directive bind put the  internal ip address of my 
> machine?
> I have some doubts
>
>
>- The internal ip address of my machine is 172.31.60.141
>
>
> root@ip-172-31-60-141:/etc/nginx/sites-enabled# ifconfig 
> eth0  Link encap:Ethernet  HWaddr 12:73:40:a8:59:99  
>   inet addr:172.31.60.141  Bcast:172.31.63.255  Mask:255.255.240.0
>   inet6 addr: fe80::1073:40ff:fea8:5999/64 Scope:Link
>   UP BROADCAST RUNNING MULTICAST  MTU:9001  Metric:1
>   RX packets:220239 errors:0 dropped:0 overruns:0 frame:0
>   TX packets:76169 errors:0 dropped:0 overruns:0 carrier:0
>   collisions:0 txqueuelen:1000 
>   RX bytes:238957069 (238.9 MB)  TX bytes:13656430 (13.6 MB)
>
> loLink encap:Local Loopback  
>   inet addr:127.0.0.1  Mask:255.0.0.0
>   inet6 addr: ::1/128 Scope:Host
>   UP LOOPBACK RUNNING  MTU:65536  Metric:1
>   RX packets:53064 errors:0 dropped:0 overruns:0 frame:0
>   TX packets:53064 errors:0 dropped:0 overruns:0 carrier:0
>   collisions:0 txqueuelen:0 
>   RX bytes:16846573 (16.8 MB)  TX bytes:16846573 (16.8 MB)
>
> root@ip-172-31-60-141:/etc/nginx/sites-enabled# 
>
> But in my dashboard console, the dns public of my ec2 instance is:
> ec2-52-90-253-22.compute-1.amazonaws.com, in fact, you can copy this url 
> in a browser...
>
> I don't know that value of address put in my gunicorn_config.py in the 
> directive bind.
> I put the internal ip address but does not work my server deployment
>
> And my nginx configuration is the following:
>
> /etc/nginx/sites-enabled/myproject , in which I unknown if in the 
> server_name and proxy_pass directives I should fix some values too..
> server {
> *server_name yourdomainorip.com ;*
> access_log off;
> location / {
> *proxy_pass http://127.0.0.1:8000 ;*
> proxy_set_header X-Forwarded-Host $server_name;
> proxy_set_header X-Real-IP $remote_addr;
> add_header P3P 'CP="ALL DSP COR PSAa PSDa OUR NOR ONL UNI COM 
> NAV"';
> }
> }
>
>  
>
>
>
>
>
> On Tuesday, February 23, 2016 at 9:37:50 AM UTC-5, Avraham Serour wrote:
>
> are you using a config file for gunicorn? in the example it tells to use:
>
> bind = '127.0.0.1:8001'
>
> are you binding to 127.0.0.1 ?
>
> On Tue, Feb 23, 2016 at 4:33 PM, Bernardo Garcia  
> wrote:
>
> Hi Mr. Avraham Serour thanks for the attention
>
> In my amazon ec2 production server I am running my Django Application 
> using nginx, and gunicorn accord to this tutorial 
> https://www.digitalocean.com/community/tutorials/how-to-install-and-configure-django-with-postgres-nginx-and-gunicorn
>
> python manage.py runserver is used just in my local development machine
>
> On Tuesday, February 23, 2016 at 9:25:36 AM UTC-5, Avraham Serour wrote:
>
> are you running django using manage.py runserver?
>
>
> On Tue, Feb 23, 2016 at 4:03 PM, Bernardo Garcia  
> wrote:
>
> Hi everyone Djangonauts
> :)
>
> Currently I am exposing a Django application (for the momento is just 
> thier users schema) with Django Rest Framework and happen that each 
> serialized model, in the url attribute, I have is the localhost machine 
> address development and don't take the hostname of my production server 
> machine which is located in amazon like as EC2 instance
>
>
> In this picture can detailed it.
>
>
> 
>
>
>
> How to make for the url of each model that I've serialized take the 
> hostna

Re: API REST - Url's Serialized models don't work with the hostname of my production server - Django Rest Framework

2016-02-23 Thread Avraham Serour
this seems to be the problem, honestly I don't have much experience with
gunicorn, I've used uwsgi and never had such problems.

I hope someone on this list with more experience with gunicorn can tell.

I suggest you either look for some other django+gunicorn tutorials and see
what they suggest or go to uwsgi like me and be happy :)



On Tue, Feb 23, 2016 at 5:42 PM, Bernardo Garcia  wrote:

> Avraham, so yes, efectively ...
>
> This is my gunicorn_config.py
>
> command = '/opt/uleague/bin/gunicorn'
> pythonpath = '/opt/uleague/pickapp'
> bind = '127.0.0.1:8000'
> workers = 3
>
>
> I will should in the directive bind put the  internal ip address of my
> machine?
> I have some doubts
>
>
>- The internal ip address of my machine is 172.31.60.141
>
>
> root@ip-172-31-60-141:/etc/nginx/sites-enabled# ifconfig
> eth0  Link encap:Ethernet  HWaddr 12:73:40:a8:59:99
>   inet addr:172.31.60.141  Bcast:172.31.63.255  Mask:255.255.240.0
>   inet6 addr: fe80::1073:40ff:fea8:5999/64 Scope:Link
>   UP BROADCAST RUNNING MULTICAST  MTU:9001  Metric:1
>   RX packets:220239 errors:0 dropped:0 overruns:0 frame:0
>   TX packets:76169 errors:0 dropped:0 overruns:0 carrier:0
>   collisions:0 txqueuelen:1000
>   RX bytes:238957069 (238.9 MB)  TX bytes:13656430 (13.6 MB)
>
> loLink encap:Local Loopback
>   inet addr:127.0.0.1  Mask:255.0.0.0
>   inet6 addr: ::1/128 Scope:Host
>   UP LOOPBACK RUNNING  MTU:65536  Metric:1
>   RX packets:53064 errors:0 dropped:0 overruns:0 frame:0
>   TX packets:53064 errors:0 dropped:0 overruns:0 carrier:0
>   collisions:0 txqueuelen:0
>   RX bytes:16846573 (16.8 MB)  TX bytes:16846573 (16.8 MB)
>
> root@ip-172-31-60-141:/etc/nginx/sites-enabled#
>
> But in my dashboard console, the dns public of my ec2 instance is:
> ec2-52-90-253-22.compute-1.amazonaws.com, in fact, you can copy this url
> in a browser...
>
> I don't know that value of address put in my gunicorn_config.py in the
> directive bind.
> I put the internal ip address but does not work my server deployment
>
> And my nginx configuration is the following:
>
> /etc/nginx/sites-enabled/myproject , in which I unknown if in the
> server_name and proxy_pass directives I should fix some values too..
> server {
> *server_name yourdomainorip.com ;*
> access_log off;
> location / {
> *proxy_pass http://127.0.0.1:8000 ;*
> proxy_set_header X-Forwarded-Host $server_name;
> proxy_set_header X-Real-IP $remote_addr;
> add_header P3P 'CP="ALL DSP COR PSAa PSDa OUR NOR ONL UNI COM
> NAV"';
> }
> }
>
>
>
>
>
>
>
> On Tuesday, February 23, 2016 at 9:37:50 AM UTC-5, Avraham Serour wrote:
>>
>> are you using a config file for gunicorn? in the example it tells to use:
>>
>> bind = '127.0.0.1:8001'
>>
>> are you binding to 127.0.0.1 ?
>>
>> On Tue, Feb 23, 2016 at 4:33 PM, Bernardo Garcia 
>> wrote:
>>
>>> Hi Mr. Avraham Serour thanks for the attention
>>>
>>> In my amazon ec2 production server I am running my Django Application
>>> using nginx, and gunicorn accord to this tutorial
>>> https://www.digitalocean.com/community/tutorials/how-to-install-and-configure-django-with-postgres-nginx-and-gunicorn
>>>
>>> python manage.py runserver is used just in my local development machine
>>>
>>> On Tuesday, February 23, 2016 at 9:25:36 AM UTC-5, Avraham Serour wrote:

 are you running django using manage.py runserver?


 On Tue, Feb 23, 2016 at 4:03 PM, Bernardo Garcia 
 wrote:

> Hi everyone Djangonauts
> :)
>
> Currently I am exposing a Django application (for the momento is just
> thier users schema) with Django Rest Framework and happen that each
> serialized model, in the url attribute, I have is the localhost machine
> address development and don't take the hostname of my production server
> machine which is located in amazon like as EC2 instance
>
>
> In this picture can detailed it.
>
>
> 
>
>
>
> How to make for the url of each model that I've serialized take the
> hostname of the production machine in which the application is deployed? 
> In
> this case, an amazon ec2 instance ...
>
>
> These are my serialized models userprofiles/serializers.py
>
>
> from django.contrib.auth.models import Groupfrom .models import User, 
> PlayerProfile, CoachProfile, ViewerProfilefrom rest_framework import 
> serializers
> # Serializers define the API representation# Exponse the model and their 
> fieldsclass UserSerializer(serializers.HyperlinkedModelSerializer):
> class Meta:
> model = User
> fields = ('url','id', 'username', 
> 'password','first_name','last_name','email','is_active',
>   

Re: API REST - Url's Serialized models don't work with the hostname of my production server - Django Rest Framework

2016-02-23 Thread Fellipe Henrique
Sorry to reply your post, but.. how do you show all api link? there's any
settings for these? I asking because, when I try on my api, show me 404
page...




T.·.F.·.A.·. S+F
*Fellipe Henrique P. Soares*

e-mail: > echo "lkrrovknFmsgor4ius" | perl -pe \ 's/(.)/chr(ord($1)-2*3)/ge'
*Fedora Ambassador: https://fedoraproject.org/wiki/User:Fellipeh
*
*Blog: *http:www.fellipeh.eti.br
*GitHub: https://github.com/fellipeh *
*Twitter: @fh_bash*

On Tue, Feb 23, 2016 at 12:42 PM, Bernardo Garcia 
wrote:

> Avraham, so yes, efectively ...
>
> This is my gunicorn_config.py
>
> command = '/opt/uleague/bin/gunicorn'
> pythonpath = '/opt/uleague/pickapp'
> bind = '127.0.0.1:8000'
> workers = 3
>
>
> I will should in the directive bind put the  internal ip address of my
> machine?
> I have some doubts
>
>
>- The internal ip address of my machine is 172.31.60.141
>
>
> root@ip-172-31-60-141:/etc/nginx/sites-enabled# ifconfig
> eth0  Link encap:Ethernet  HWaddr 12:73:40:a8:59:99
>   inet addr:172.31.60.141  Bcast:172.31.63.255  Mask:255.255.240.0
>   inet6 addr: fe80::1073:40ff:fea8:5999/64 Scope:Link
>   UP BROADCAST RUNNING MULTICAST  MTU:9001  Metric:1
>   RX packets:220239 errors:0 dropped:0 overruns:0 frame:0
>   TX packets:76169 errors:0 dropped:0 overruns:0 carrier:0
>   collisions:0 txqueuelen:1000
>   RX bytes:238957069 (238.9 MB)  TX bytes:13656430 (13.6 MB)
>
> loLink encap:Local Loopback
>   inet addr:127.0.0.1  Mask:255.0.0.0
>   inet6 addr: ::1/128 Scope:Host
>   UP LOOPBACK RUNNING  MTU:65536  Metric:1
>   RX packets:53064 errors:0 dropped:0 overruns:0 frame:0
>   TX packets:53064 errors:0 dropped:0 overruns:0 carrier:0
>   collisions:0 txqueuelen:0
>   RX bytes:16846573 (16.8 MB)  TX bytes:16846573 (16.8 MB)
>
> root@ip-172-31-60-141:/etc/nginx/sites-enabled#
>
> But in my dashboard console, the dns public of my ec2 instance is:
> ec2-52-90-253-22.compute-1.amazonaws.com, in fact, you can copy this url
> in a browser...
>
> I don't know that value of address put in my gunicorn_config.py in the
> directive bind.
> I put the internal ip address but does not work my server deployment
>
> And my nginx configuration is the following:
>
> /etc/nginx/sites-enabled/myproject , in which I unknown if in the
> server_name and proxy_pass directives I should fix some values too..
> server {
> *server_name yourdomainorip.com ;*
> access_log off;
> location / {
> *proxy_pass http://127.0.0.1:8000 ;*
> proxy_set_header X-Forwarded-Host $server_name;
> proxy_set_header X-Real-IP $remote_addr;
> add_header P3P 'CP="ALL DSP COR PSAa PSDa OUR NOR ONL UNI COM
> NAV"';
> }
> }
>
>
>
>
>
>
>
> On Tuesday, February 23, 2016 at 9:37:50 AM UTC-5, Avraham Serour wrote:
>>
>> are you using a config file for gunicorn? in the example it tells to use:
>>
>> bind = '127.0.0.1:8001'
>>
>> are you binding to 127.0.0.1 ?
>>
>> On Tue, Feb 23, 2016 at 4:33 PM, Bernardo Garcia 
>> wrote:
>>
>>> Hi Mr. Avraham Serour thanks for the attention
>>>
>>> In my amazon ec2 production server I am running my Django Application
>>> using nginx, and gunicorn accord to this tutorial
>>> https://www.digitalocean.com/community/tutorials/how-to-install-and-configure-django-with-postgres-nginx-and-gunicorn
>>>
>>> python manage.py runserver is used just in my local development machine
>>>
>>> On Tuesday, February 23, 2016 at 9:25:36 AM UTC-5, Avraham Serour wrote:

 are you running django using manage.py runserver?


 On Tue, Feb 23, 2016 at 4:03 PM, Bernardo Garcia 
 wrote:

> Hi everyone Djangonauts
> :)
>
> Currently I am exposing a Django application (for the momento is just
> thier users schema) with Django Rest Framework and happen that each
> serialized model, in the url attribute, I have is the localhost machine
> address development and don't take the hostname of my production server
> machine which is located in amazon like as EC2 instance
>
>
> In this picture can detailed it.
>
>
> 
>
>
>
> How to make for the url of each model that I've serialized take the
> hostname of the production machine in which the application is deployed? 
> In
> this case, an amazon ec2 instance ...
>
>
> These are my serialized models userprofiles/serializers.py
>
>
> from django.contrib.auth.models import Groupfrom .models import User, 
> PlayerProfile, CoachProfile, ViewerProfilefrom rest_framework import 
> serializers
> # Serializers define the API representation# Exponse the model and their 
> fieldsclass UserSerializer(serializers.HyperlinkedModelSerializer):
> 

Re: API REST - Url's Serialized models don't work with the hostname of my production server - Django Rest Framework

2016-02-23 Thread Bernardo Garcia
Avraham, so yes, efectively ...

This is my gunicorn_config.py

command = '/opt/uleague/bin/gunicorn'
pythonpath = '/opt/uleague/pickapp'
bind = '127.0.0.1:8000'
workers = 3


I will should in the directive bind put the  internal ip address of my 
machine?
I have some doubts


   - The internal ip address of my machine is 172.31.60.141
   

root@ip-172-31-60-141:/etc/nginx/sites-enabled# ifconfig 
eth0  Link encap:Ethernet  HWaddr 12:73:40:a8:59:99  
  inet addr:172.31.60.141  Bcast:172.31.63.255  Mask:255.255.240.0
  inet6 addr: fe80::1073:40ff:fea8:5999/64 Scope:Link
  UP BROADCAST RUNNING MULTICAST  MTU:9001  Metric:1
  RX packets:220239 errors:0 dropped:0 overruns:0 frame:0
  TX packets:76169 errors:0 dropped:0 overruns:0 carrier:0
  collisions:0 txqueuelen:1000 
  RX bytes:238957069 (238.9 MB)  TX bytes:13656430 (13.6 MB)

loLink encap:Local Loopback  
  inet addr:127.0.0.1  Mask:255.0.0.0
  inet6 addr: ::1/128 Scope:Host
  UP LOOPBACK RUNNING  MTU:65536  Metric:1
  RX packets:53064 errors:0 dropped:0 overruns:0 frame:0
  TX packets:53064 errors:0 dropped:0 overruns:0 carrier:0
  collisions:0 txqueuelen:0 
  RX bytes:16846573 (16.8 MB)  TX bytes:16846573 (16.8 MB)

root@ip-172-31-60-141:/etc/nginx/sites-enabled# 

But in my dashboard console, the dns public of my ec2 instance is:
ec2-52-90-253-22.compute-1.amazonaws.com, in fact, you can copy this url in 
a browser...

I don't know that value of address put in my gunicorn_config.py in the 
directive bind.
I put the internal ip address but does not work my server deployment

And my nginx configuration is the following:

/etc/nginx/sites-enabled/myproject , in which I unknown if in the 
server_name and proxy_pass directives I should fix some values too..
server {
*server_name yourdomainorip.com;*
access_log off;
location / {
*proxy_pass http://127.0.0.1:8000;*
proxy_set_header X-Forwarded-Host $server_name;
proxy_set_header X-Real-IP $remote_addr;
add_header P3P 'CP="ALL DSP COR PSAa PSDa OUR NOR ONL UNI COM 
NAV"';
}
}

 





On Tuesday, February 23, 2016 at 9:37:50 AM UTC-5, Avraham Serour wrote:
>
> are you using a config file for gunicorn? in the example it tells to use:
>
> bind = '127.0.0.1:8001'
>
> are you binding to 127.0.0.1 ?
>
> On Tue, Feb 23, 2016 at 4:33 PM, Bernardo Garcia  > wrote:
>
>> Hi Mr. Avraham Serour thanks for the attention
>>
>> In my amazon ec2 production server I am running my Django Application 
>> using nginx, and gunicorn accord to this tutorial 
>> https://www.digitalocean.com/community/tutorials/how-to-install-and-configure-django-with-postgres-nginx-and-gunicorn
>>
>> python manage.py runserver is used just in my local development machine
>>
>> On Tuesday, February 23, 2016 at 9:25:36 AM UTC-5, Avraham Serour wrote:
>>>
>>> are you running django using manage.py runserver?
>>>
>>>
>>> On Tue, Feb 23, 2016 at 4:03 PM, Bernardo Garcia  
>>> wrote:
>>>
 Hi everyone Djangonauts
 :)

 Currently I am exposing a Django application (for the momento is just 
 thier users schema) with Django Rest Framework and happen that each 
 serialized model, in the url attribute, I have is the localhost machine 
 address development and don't take the hostname of my production server 
 machine which is located in amazon like as EC2 instance


 In this picture can detailed it.


 



 How to make for the url of each model that I've serialized take the 
 hostname of the production machine in which the application is deployed? 
 In 
 this case, an amazon ec2 instance ...


 These are my serialized models userprofiles/serializers.py 


 from django.contrib.auth.models import Groupfrom .models import User, 
 PlayerProfile, CoachProfile, ViewerProfilefrom rest_framework import 
 serializers
 # Serializers define the API representation# Exponse the model and their 
 fieldsclass 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 = CoachProf

Re: API REST - Url's Serialized models don't work with the hostname of my production server - Django Rest Framework

2016-02-23 Thread Avraham Serour
are you using a config file for gunicorn? in the example it tells to use:

bind = '127.0.0.1:8001'

are you binding to 127.0.0.1 ?

On Tue, Feb 23, 2016 at 4:33 PM, Bernardo Garcia  wrote:

> Hi Mr. Avraham Serour thanks for the attention
>
> In my amazon ec2 production server I am running my Django Application
> using nginx, and gunicorn accord to this tutorial
> https://www.digitalocean.com/community/tutorials/how-to-install-and-configure-django-with-postgres-nginx-and-gunicorn
>
> python manage.py runserver is used just in my local development machine
>
> On Tuesday, February 23, 2016 at 9:25:36 AM UTC-5, Avraham Serour wrote:
>>
>> are you running django using manage.py runserver?
>>
>>
>> On Tue, Feb 23, 2016 at 4:03 PM, Bernardo Garcia 
>> wrote:
>>
>>> Hi everyone Djangonauts
>>> :)
>>>
>>> Currently I am exposing a Django application (for the momento is just
>>> thier users schema) with Django Rest Framework and happen that each
>>> serialized model, in the url attribute, I have is the localhost machine
>>> address development and don't take the hostname of my production server
>>> machine which is located in amazon like as EC2 instance
>>>
>>>
>>> In this picture can detailed it.
>>>
>>>
>>> 
>>>
>>>
>>>
>>> How to make for the url of each model that I've serialized take the
>>> hostname of the production machine in which the application is deployed? In
>>> this case, an amazon ec2 instance ...
>>>
>>>
>>> These are my serialized models userprofiles/serializers.py
>>>
>>>
>>> from django.contrib.auth.models import Groupfrom .models import User, 
>>> PlayerProfile, CoachProfile, ViewerProfilefrom rest_framework import 
>>> serializers
>>> # Serializers define the API representation# Exponse the model and their 
>>> fieldsclass 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 urls.py global file (not belont to userprofiles application
>>> that contain all the serialized models.)
>>>
>>>
>>> from django.conf.urls import url, includefrom django.contrib import admin
>>> from .views import home, home_files
>>> from rest_framework import routersfrom 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(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 in where I have expose the
>>> models serializeds
>>>
>>>
>>> from django.shortcuts import renderfrom django.contrib.auth.models import 
>>> Groupfrom .models import User, PlayerProfile, CoachProfile, ViewerProfile
>>> from rest_framework import viewsetsfrom .serializers import UserSerializer, 
>>> GroupSerializer, PlayerProfileSerializer, CoachProfileSerializer, 
>>> ViewerProfileSerializer
>>> # Create your views here.
>>> # Viewsets define the behavior of the viewclass 
>>> 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 gr

Re: API REST - Url's Serialized models don't work with the hostname of my production server - Django Rest Framework

2016-02-23 Thread Bernardo Garcia
Hi Mr. Avraham Serour thanks for the attention

In my amazon ec2 production server I am running my Django Application using 
nginx, and gunicorn accord to this 
tutorial 
https://www.digitalocean.com/community/tutorials/how-to-install-and-configure-django-with-postgres-nginx-and-gunicorn

python manage.py runserver is used just in my local development machine

On Tuesday, February 23, 2016 at 9:25:36 AM UTC-5, Avraham Serour wrote:
>
> are you running django using manage.py runserver?
>
>
> On Tue, Feb 23, 2016 at 4:03 PM, Bernardo Garcia  > wrote:
>
>> Hi everyone Djangonauts
>> :)
>>
>> Currently I am exposing a Django application (for the momento is just 
>> thier users schema) with Django Rest Framework and happen that each 
>> serialized model, in the url attribute, I have is the localhost machine 
>> address development and don't take the hostname of my production server 
>> machine which is located in amazon like as EC2 instance
>>
>>
>> In this picture can detailed it.
>>
>>
>> 
>>
>>
>>
>> How to make for the url of each model that I've serialized take the 
>> hostname of the production machine in which the application is deployed? In 
>> this case, an amazon ec2 instance ...
>>
>>
>> These are my serialized models userprofiles/serializers.py 
>>
>>
>> from django.contrib.auth.models import Groupfrom .models import User, 
>> PlayerProfile, CoachProfile, ViewerProfilefrom rest_framework import 
>> serializers
>> # Serializers define the API representation# Exponse the model and their 
>> fieldsclass 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 urls.py global file (not belont to userprofiles application 
>> that contain all the serialized models.)
>>
>>
>> from django.conf.urls import url, includefrom django.contrib import admin
>> from .views import home, home_files
>> from rest_framework import routersfrom 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(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 in where I have expose the 
>> models serializeds
>>
>>
>> from django.shortcuts import renderfrom django.contrib.auth.models import 
>> Groupfrom .models import User, PlayerProfile, CoachProfile, ViewerProfile
>> from rest_framework import viewsetsfrom .serializers import UserSerializer, 
>> GroupSerializer, PlayerProfileSerializer, CoachProfileSerializer, 
>> ViewerProfileSerializer
>> # Create your views here.
>> # Viewsets define the behavior of the viewclass 
>> 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()
>>  

Re: API REST - Url's Serialized models don't work with the hostname of my production server - Django Rest Framework

2016-02-23 Thread Avraham Serour
are you running django using manage.py runserver?


On Tue, Feb 23, 2016 at 4:03 PM, Bernardo Garcia  wrote:

> Hi everyone Djangonauts
> :)
>
> Currently I am exposing a Django application (for the momento is just
> thier users schema) with Django Rest Framework and happen that each
> serialized model, in the url attribute, I have is the localhost machine
> address development and don't take the hostname of my production server
> machine which is located in amazon like as EC2 instance
>
>
> In this picture can detailed it.
>
>
> 
>
>
>
> How to make for the url of each model that I've serialized take the
> hostname of the production machine in which the application is deployed? In
> this case, an amazon ec2 instance ...
>
>
> These are my serialized models userprofiles/serializers.py
>
>
> from django.contrib.auth.models import Groupfrom .models import User, 
> PlayerProfile, CoachProfile, ViewerProfilefrom rest_framework import 
> serializers
> # Serializers define the API representation# Exponse the model and their 
> fieldsclass 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 urls.py global file (not belont to userprofiles application
> that contain all the serialized models.)
>
>
> from django.conf.urls import url, includefrom django.contrib import admin
> from .views import home, home_files
> from rest_framework import routersfrom 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(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 in where I have expose the
> models serializeds
>
>
> from django.shortcuts import renderfrom django.contrib.auth.models import 
> Groupfrom .models import User, PlayerProfile, CoachProfile, ViewerProfile
> from rest_framework import viewsetsfrom .serializers import UserSerializer, 
> GroupSerializer, PlayerProfileSerializer, CoachProfileSerializer, 
> ViewerProfileSerializer
> # Create your views here.
> # Viewsets define the behavior of the viewclass 
> 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
>
>
> Any orientation or support about it, I will be grateful :)
>
> --
> Y

API REST - Url's Serialized models don't work with the hostname of my production server - Django Rest Framework

2016-02-23 Thread Bernardo Garcia
Hi everyone Djangonauts
:)

Currently I am exposing a Django application (for the momento is just thier 
users schema) with Django Rest Framework and happen that each serialized 
model, in the url attribute, I have is the localhost machine address 
development and don't take the hostname of my production server machine 
which is located in amazon like as EC2 instance


In this picture can detailed it.






How to make for the url of each model that I've serialized take the 
hostname of the production machine in which the application is deployed? In 
this case, an amazon ec2 instance ...


These are my serialized models userprofiles/serializers.py 


from django.contrib.auth.models import Groupfrom .models import User, 
PlayerProfile, CoachProfile, ViewerProfilefrom rest_framework import serializers
# Serializers define the API representation# Exponse the model and their 
fieldsclass 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 urls.py global file (not belont to userprofiles application that 
contain all the serialized models.)


from django.conf.urls import url, includefrom django.contrib import admin
from .views import home, home_files
from rest_framework import routersfrom 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(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 in where I have expose the models 
serializeds


from django.shortcuts import renderfrom django.contrib.auth.models import 
Groupfrom .models import User, PlayerProfile, CoachProfile, ViewerProfile
from rest_framework import viewsetsfrom .serializers import UserSerializer, 
GroupSerializer, PlayerProfileSerializer, CoachProfileSerializer, 
ViewerProfileSerializer
# Create your views here.
# Viewsets define the behavior of the viewclass 
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


Any orientation or support about it, I will be grateful :)

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/dj