I created an API for the company i work however i would like people having access in the same company network, how can i achieve this? I currently modified the allowed host as follow:
ALLOWED_HOSTS = ['127.0.0.1', 'localhost','192.168.6.7', '127.0.1.1', '161.19.109.123']
however only work in my computer under IP: 127.0.0.1:8000, any suggestions? FYI i do not have administrator privilege.
Try this to access project in a lan server
python manage.py runserver your_ip:port.
For example
my system IP address is something like 192.168.12.135, when we run run django development server its runs at localhost:8000, i mean with the system IP address and with a port 8000 like 192.168.12.135:8000 right.
it'll be accessible if you're running through apache or any other webservers other than the development server.
I would advice you to host and use a local apache server rather than using development server. Doing so, you can foresee the issues you'll be facing when moving to production.
Related
I have finished a Django project and want to deploy it over Apache2 locally over LAN. I have figured out how to connect Django with Apache2 using mod_wsgi and it worked great because I was able to use Apace2 to actually host Django on localhost.
Now I want to actually make this project available to anyone on my local network. Like for instance assuming that my local IP address was 10.10.10.51 I could go to a different device connected to my local network and type in 10.10.10.51 to actually get to the Apache2 server homepage. It does that successfully.
My Django project is hosted on my Apache2 localhost server at djangoproject.localhost and it works fine just on my PC. When I move on to the other PC and go to djangoproject.localhost the site is not up there. Yes they are both connected to the same LAN network.
I used this tutorial to host Django on Apache2: Host Django on Apache2 with mod_wsgi
I think that you have to configure something called port forwarding in your home modem, this video could help: https://www.youtube.com/watch?v=6gkoDQUQSLc
I suppose you are on windows ...
If you run your app on pc1 and want to call it from pc2, you need to call it either
via ip adress of pc1
via djangoproject.localhost
but then you need to edit the hosts file on pc2:
C:\Windows\System32\drivers\etc\hosts
and add something like (x.x.x.x = ip adress of pc1)
x.x.x.x djangoproject.localhost
because on pc2 your brwoser does not know what to do with djangoproject.localhost as in a LAN in general you do not have a local domain name server running.
If your firewall on pc1 blocks access to apache you need to got to "windows defender firewall" (type "defender" in search bar) and add a rule for apache application.
I've been working on a website for the past month, and now its time for me to host the django website onto a private server. Is there a detailed method on how I'm supposed to host the website onto a specific IP address assigned to my system?
This is my first time dealing with hosting a server and i dont know much about it.
Also, once i host it, How do i change the link from being the IP address to an actual link like "12345678.com" or something like that?
(The website should be hosted in such a way that only the people who are in the same network/lan connection should have access to the website.)
I have wamp on the system and the system has a Windows Server OS (if this info helps)
you can run your codes with manage command like this
python manage.py runserver 0.0.0.0:8000
but its strongly recommended to run your code with a web server like nginx or apache read this tutorial to run your site on a linux server
https://www.digitalocean.com/community/tutorials/how-to-set-up-uwsgi-and-nginx-to-serve-python-apps-on-ubuntu-14-04
on windows you can use IIS but its not recommended. its performance is not good
to use 1234567890.com instead of using server ip address you must setup a DNS server on your local network. in linux you can use bind and windows server have its own DNS server. but in your DHCP configuration you must set this DNS server as clients DNS.
I use the rest framework write APIs, and when I runserver the website
I can access the APIs in the development machine(the intranet ip is 10.10.10.111):
But how can I access the API in other computer which is in the 10.10.10.0/24 intranet?
If can, this will become more convenient for our team to debugging.
To make your development server view-able to other machines on the network, use its own IP address (e.g. 10.10.10.111) or 0.0.0.0.
See the examples for running django projects on different ports and ip address.
The command will be:
django-admin runserver 0.0.0.0:<port>
or
python manage.py runserver 0.0.0.0:<port>
You can then visit the site in 10.10.10.111:<port> or <your.machine.ip.address:port> from same network.
What #salman said plus: This is most likely the host computers firewall blocking the packets. Depending on your OS try to selectively open this port.
Edit
Most likely the firewall on the host (*) machine will block the traffic. Also ask your admin if a firewall in the network blocks the port.
*) host meaning „the machine running the server
Runserver in Django project:
python manage.py runserver 0.0.0.0:<port>
stop the firewall in your develop OS, such as the CentOS7:
systemctl stop firewalld.service
then add the ALLOW_HOST in your project settings.py,
because your computer are connected use inner network, you can allow all:
ALLOWED_HOSTS = ['*']
I have installed Django server and it can be accessed as below
http://localhost:8000/get-sms/
http://127.0.0.1:8000/get-sms/
suppose My IP is x.x.x.x .
From another PC under the same network when I do
my-ip:8000/get-sms/
but it is not working.
I can easily ping my IP with that computer.
Moreover, on my port 81, I have apache, which is easily accessible like below
http:///my-ip:81
What can be the issue? Do I need something extra in Django
Running the Django Development Server
This is what you're looking for. To help you further, here is what you should do:
python manage.py runserver 0.0.0.0:8000
By the way, this may be a duplicate of this question.
Here is what the documentation says:
Note that the default IP address, 127.0.0.1, is not accessible from
other machines on your network. To make your development server
viewable to other machines on the network, use its own IP address
(e.g. 192.168.2.1) or 0.0.0.0.
To add to #Depado 's answer you may need to add your LAN IP address to ALLOWED_HOSTS in the settings.py along with localhost. it would look like,
ALLOWED_HOSTS = ["localhost", "192.168.8.160"]
(if localhost isn't working use 127.0.0.1 as suggested by #Sabito 錆兎)
You can use https://ngrok.com/ this will expose your local web server to the internet/public.
Everywhere I looked, I kept seeing the answer to use the terminal command:
python manage.py runserver 0.0.0.0:8000
That works, but not if you want to run a remote debugger across the LAN (in my case VSCode), which launches the server automatically without a chance to modify the host ip address. However, I found a permanent solution:
Open: ./env/lib/python3.8/site-packages/django/core/management/commands/runserver.py
Search for: self.addr = ''
Replace '' with '0' and save. ('0' is shorthand for '0.0.0.0')
Now if you run: python manage.py runserver it is open to the local network, outputting: Starting development server at http://0:8000/
Importantly, the debugger now launches the server at http://0:8000/
If you haven't already, remember to add your client to allowed hosts in settings.py: ALLOWED_HOSTS = ["*"]
Blockquote
I've been tasked by my programming teacher to learn Django. However, I need to code on a command line linux box and therefore cannot access the web page from said linux box.
To test, I need to host it on the local IP of the computer rather than localhost. I’m currently running the Django development server using this command:
python manage.py runserver 0.0.0.0:8000
Firefox and Chrome can access the development server at the Linux box’s IP address, but Internet Explorer can’t.
Unfortunately (I am said teacher), I can't provide a linux host - only a linux server and a windows host to do development on.
He's actually running the web server correctly, with the command provided by Paul. But for some reason, it's only visible in Firefox/Chrome, IE just provides a generic "Webpage cannot be displayed"
But this problem can be solved by using the entire address: http:// isn't optional like it is in Chrome and Firefox.
When you run the development server, you can make it available on the local network by specifying the IP address 0.0.0.0 for it, like this:
python manage.py runserver 0.0.0.0:8000
If your Linux box’s local IP address is e.g. 192.168.1.37, you’d access the development server at:
http://192.168.1.37:8000
Setup nginx to listen on a public port and proxy all of the requests to the django runserver.
You need to specify the IP clearly in the command line like this in order to let other clients to access. You also have to enable the port 8000 in the firewall:
python manage.py runserver 192.168.1.37:8000