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
Percy
Percy15mo ago
Project ID: N/A
yori_39035
yori_39035OP15mo ago
N/A
MantisInABox
MantisInABox15mo ago
Is your app listening on Port 8000? If so, you will want to set an environment variable of PORT to 8000
yori_39035
yori_39035OP15mo ago
Thanks, that's what I already did
MantisInABox
MantisInABox15mo ago
Okay, and it is still not working?
yori_39035
yori_39035OP15mo ago
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
MantisInABox
MantisInABox15mo ago
Did you add the URL to your allowed hosts in your django settings.py file?
yori_39035
yori_39035OP15mo ago
I believe this adds all available hosts? ALLOWED_HOSTS = ["*"] That's what I have
MantisInABox
MantisInABox15mo ago
Yeah, that should work for sure...
yori_39035
yori_39035OP15mo ago
Do I need to also perhaps add this to trusted origins?
ALLOWED_HOSTS = [""]

Comment out the following line and place your railway URL, and your production URL in the array.
CSRF_TRUSTED_ORIGINS = ["
"]
ALLOWED_HOSTS = [""]

Comment out the following line and place your railway URL, and your production URL in the array.
CSRF_TRUSTED_ORIGINS = ["
"]
MantisInABox
MantisInABox15mo ago
You might need to, especially if you are passing form data
yori_39035
yori_39035OP15mo ago
Hmmm, still not working. Maybe some sort of Django authentication thing
MantisInABox
MantisInABox15mo ago
It's possible. Are you seeing any errors in your deploy logs?
yori_39035
yori_39035OP15mo ago
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
MantisInABox
MantisInABox15mo ago
Are you able to share your git repo?
yori_39035
yori_39035OP15mo ago
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:
yori_39035
yori_39035OP15mo ago
No description
yori_39035
yori_39035OP15mo ago
Railway:
yori_39035
yori_39035OP15mo ago
No description
yori_39035
yori_39035OP15mo ago
I am just using the Django Starter REST repo given by Railway
MantisInABox
MantisInABox15mo ago
Is the API currently running on your local machine?
yori_39035
yori_39035OP15mo ago
yes
MantisInABox
MantisInABox15mo ago
Is the service running on railway connected to the same database as the server running on your local machine?
yori_39035
yori_39035OP15mo ago
yes, but i'm not returning data from a database currently, just dummy test data in the python script
MantisInABox
MantisInABox15mo ago
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
yori_39035
yori_39035OP15mo ago
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!!!
Want results from more Discord servers?
Add your server