How to allow others to connect to my Django website? - python

Now that I have created a website, I wish the users can connect to my website within a local network. However my website now can only be accessible from the localhost (my pc), the others are not able to connect to my website when typing my ip address for example xxx.xxx.xxx.xxx:8000 on their browser. I launch the service on my localhost using # python manage.py runserver. May I know if there is a way/command to allow the others to connect to my website?
Note: I have tried # python manage.py runserver 0.0.0.0:8000 as well, which allow all incoming, but it didn't work.

In settings.py write
ALLOWED_HOSTS = ['*'] and run python manage.py runserver 0.0.0.0:8000
Note: you can use any port instead of 8000

There are steps to resolve this problem are:
1. Use http://<your ip address> than https
2. Then in settings.py write
ALLOWED_HOSTS = ['*']
3. Finally ran the server with:
python manage.py runserver 0.0.0.0:8000

Related

The Django admin site

I start the development server and explore it. When I open the Web browser and go to “/admin/” on my local domain, http://127.0.0.1:8000/admin/.I face this screen:
Did you migrate all such as db or session, etc..?
Run 'python manage.py migrate' to apply them.
Check port or open another port
ex:
python manage.py runserver 0.0.0.0:80
Please open cmd and enter your project path
And then enter the following commands in cmd
Note: If you have venv, activate it beforehand
python ./manage.py migrate
python ./manage.py runserver

Why I failed to connect to the django server?

I'm following a tutorial, using this command in a Docker container to start the Django server:
python3 manage.py runserver 0.0.0.0:8000
But I can not connect to it by IP.
I am sure that I have already open the 8000 port and this port is on listening. By the way, I use the ubuntu and set the server in the aliyun.
At First Django works on port 8000 not on 8080. So you should use python manage.py runserver 0.0.0.0:8000. You can eazly kill port in linux server by type: fuser 8080/tcp

Accessing containerized Django app from ECS public IPv4 endpoint

I have a dockerized django app that is stored in ECR. When I set-up a new ECS cluster (using Fargate), this image loads correctly and I can see the logs in Cloudwatch:
20:12:21 Operations to perform:
20:12:21 Apply all migrations: admin, auth, contenttypes, sessions
20:12:21 Running migrations:
20:12:21 No migrations to apply.
20:12:23 No changes detected
20:12:25 Watching for file changes with StatReloader
20:12:25 Performing system checks...
20:12:25 System check identified no issues (0 silenced).
20:12:26 June 22, 2019 - 20:12:26
20:12:26 Django version 2.2.2, using settings 'config.settings'
20:12:26 Starting development server at http://127.0.0.1:8000/
20:12:26 Quit the server with CONTROL-C.
but when I got to the public ipv4 listed under the task network details, and go to :8000 in my browser, nothing loads and I dont see any requests going to the server in the container in cloud watch.
I'm wondering if the issue is related to using:
python manage.py runserver 0.0.0.0:8000 in my container set-up or alternatively, a setting in the security group, etc.
But i've allowed inbound traffic to 127.0.0.1 & 0.0.0.0 port 8000 inside the settings there already.
I'm somewhat at a loss as I've looked around at a variety of documentation and I seem to have my configuration set similarly.
You need to map your host port to container port if your container is running in bridge mod Something like docker run -p <port>:8000.to view it on browser as public_ip:port Similar configuration you have to do in fargate.
Check if in AWS Control panel for Fargate this particular container definition have correct port mapping.
In your case, you need to map to port: 8000 as your app is listening on that port. Also, you need to create that app in a container is listening to 0.0.0.0, not 127.0.0.1 ( At least from log port I can see you bind it to 127.0.0.1

Running Django with gunicorn: Bad Request (400)

I am following this tutorial to set up a Django application and serve it with Gunicorn on a Debian DigitalOcean server: http://michal.karzynski.pl/blog/2013/06/09/django-nginx-gunicorn-virtualenv-supervisor/
I have got as far as the section starting "Now that you have gunicorn, you can test whether it can serve your Django application by running the following command". Now I'm stuck.
In other words, I can successfully run the application using python manage.py runserver, but not by using gunicorn.
I've successfully accessed my app with:
$ python manage.py runserver xx.xx.xx.xx:8000
Now from the same directory, I'm trying to run:
$ gunicorn my_django.wsgi:application --bind xx.xx.xx.xx:8001
It appears to start OK, but when I go to http://xx.xx.xx.xx:8001, I see:
Bad Request (400)
I'm not sure how to debug this: there's nothing in /var/log/gunicorn/.
I have set ALLOWED_HOSTS=['xx.xx.xx.xx'] in my settings file.
UPDATE: Being an idiot: gunicorn was looking in production settings file, not local settings file. Setting the ALLOWED_HOSTS in production settings fixed it.
I'd still really like to know how to debug problems like this though.
The answer: gunicorn was looking in production settings file, not local settings file. Setting the ALLOWED_HOSTS in production settings fixed it.

How start server Django in the VM (Vagrant)

i want install Django in my VM created with PuPHPpet (Vagrant), then when i start the server with
python manage.py runserver
My project is normally available in 127.0.0.1:8000
But i have unreachable web page, then i try
python manage.py runserver ipvm:8000 and others ports
I have always unreachable web page
So, i have found in this forum
0.0.0.0:8000
And i have again unreachable web page, Why ? How can start my server in my VM ?
You have to forward the port from Vagrant to your local machine. You can add a line like this to your Vagrantfile:
config.vm.network :forwarded_port, host: 8001, guest: 8000
And then run this in the Vagrant VM:
python manage.py runserver 0.0.0.0:8000
And on your host machine, go to http://localhost:8001 to view the webpage.
Run python manage.py runserver 0:8000. It worked for me
You have to forward the port from Vagrant to your local machine.
config.vm.network :forwarded_port, host: 8001, guest: 8000
Yo need to add IP to ALLOWED_HOST in your setting.py file
0.0.0.0 to the ALLOWED_HOSTS in your settings.py
Run Project
python manage.py runserver 0.0.0.0:8000

Categories