http://0.0.0.0:8000 to url
I am using a Django REST framework. When I query the URL at 0.0.0.0:8000 I can get a response, but at the URL I get the page is not found error. How can I link the two?
26 Replies
Project ID:
N/A
N/A
Is your app listening on Port 8000? If so, you will want to set an environment variable of
PORT
to 8000
Thanks, that's what I already did
Okay, and it is still not working?
Still not working. The end point works at: http://0.0.0.0:8000/join-codes/ but does not work at the domains.
At https://django-rest-starter-production-xxxx.up.railway.app/join-codes/ I return an empty [] get response where the above returns json data
Is this something I have to configure within Django?
* at the railway domain
Did you add the URL to your allowed hosts in your django settings.py file?
I believe this adds all available hosts?
ALLOWED_HOSTS = ["*"]
That's what I haveYeah, that should work for sure...
Do I need to also perhaps add this to trusted origins?
You might need to, especially if you are passing form data
Hmmm, still not working. Maybe some sort of Django authentication thing
It's possible. Are you seeing any errors in your deploy logs?
No, I'm not.
The endpoint is there because when I specify a different endpoint from the one I set up I get a page not found. However, when I try the Railway domain, I get the [] JSON endpoint data.
However, at 0.0.0.0:8000/endpoint, the data returns just fine
I get the empty [] JSON endpoint data from the Railway domain
Here is the response from the Railway URL: (200 succesful REST API response but no data returned)
Summary
URL: https://django-rest-starter-production-xxxx.up.railway.app/join-codes/
Status: 200
Source: Network
Address: xxxxxx
Request
:method: GET
:scheme: https
:authority: django-rest-starter-production-xxxx.up.railway.app
:path: /join-codes/
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,/;q=0.8
Accept-Encoding: gzip, deflate, br
Accept-Language: en-US,en;q=0.9
Connection: keep-alive
Cookie: stripe_mid=f83557e6-3a42-4594-bafb-3c24a3bfdd8e0150bd; stripe_sid=2e6be1d1-6830-491e-8805-b12f10c8f22daf9969; ajs_anonymous_id=e9a1b8cf-e0ce-4e0e-b88c-707c374f04ba; ajs_user_id=39160776-f724-4d9e-a4b8-cd23a2df7871; csrftoken=hyPsStxpwOdc4OnEOAxHudDFxaHwI6uH
Host: django-rest-starter-production-7b48.up.railway.app
Sec-Fetch-Dest: document
Sec-Fetch-Mode: navigate
Sec-Fetch-Site: none
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.5 Safari/605.1.15
Response
:status: 200
Content-Length: 2
Content-Type: application/json
Cross-Origin-Opener-Policy: same-origin
Date: Sun, 10 Sep 2023 22:50:45 GMT
Referrer-Policy: same-origin
Server: railway
Vary: origin
X-Content-Type-Options: nosniff
X-Frame-Options: DENY
Here is the response from 0.0.0.0:8000/join-codes endpoint which returns also a successful response, but this time returns the actual data:
Summary
URL: http://0.0.0.0:8000/join-codes/
Status: 200 OK
Source: Network
Address: 127.0.0.1:8000
Request
GET /join-codes/ HTTP/1.1
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,/*;q=0.8
Accept-Encoding: gzip, deflate
Accept-Language: en-US,en;q=0.9
Connection: keep-alive
Host: 0.0.0.0:8000
Upgrade-Insecure-Requests: 1
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.5 Safari/605.1.15
Response
HTTP/1.1 200 OK
Content-Length: 178
Content-Type: application/json
Cross-Origin-Opener-Policy: same-origin
Date: Sun, 10 Sep 2023 22:53:28 GMT
Referrer-Policy: same-origin
Server: WSGIServer/0.2 CPython/3.10.9
Vary: origin
X-Content-Type-Options: nosniff
X-Frame-Options: DENY
Are you able to share your git repo?
I would have to make another one because this is the company git
However, I noticed that the header size is much larger for 0.0.0.0 url, so maybe an authentication thing?
]
0.0.0.0:
Railway:
I am just using the Django Starter REST repo given by Railway
Is the API currently running on your local machine?
yes
Is the service running on railway connected to the same database as the server running on your local machine?
yes, but i'm not returning data from a database currently, just dummy test data in the python script
Then there is an issue with your python script somewhere. Because if it is dummy data, it should be returning.
Getting results off 0.0.0.0 is not necessarily a sign of it working, as that’s just a loop back to the server you have running on your local system. You may need to add some print statement to send to your deploy logs on railway to ensure everything is working as intended
I figured out the issue! What was happening is I was not using a GET decorator for the Python method. While that method was working on local (because of following a tutorial), Django must require a decorator for security authentication from an external URL (just a guess). But that worked! Thank you so much for your help!!!