I currently have a django project that I am working on. The project is sitting on my remote webserver, and I start it by running manage.py runserver 0.0.0.0:8000. Howver, if I try to access the site via domainname.com:8000, I can't see the site.
How can I view a django project remotely like this? Do I need to do setup using apache? Punch a hole in the firewall? Is there an easy way?
This is strictly for development purposes.
You need to bind it to an IP, not 0.0.0.0.
Also, you may want to check that firewall rules are not stopping you from accessing port 8000 (I did this this morning!)
You can use ssh tunnels. It's easy to set up in Windows with Putty (look at this example for manageing postgresql) or google how to use tunnels with ssh in Linux. I think this is amazing thing, since I first time get to my databse on remote server :)
Related
I'm new to this, so I apologize if my question is a little too simplistic or I don't have the correct understanding. I can't find anything in the django guide and I'm not sure if the general port information is the same considering what i'm doing with Django.
I'm running a django runserver on '0.0.0.0:8000', which allows me to access the server remotely on another device in the same household.
Is there anything I should be doing to help protect from outside attacks as the port is open?
I believe I read that although this won't grant access to the device running the server, it can leave it vulnerable to issues. But there shouldn't be any sensitive data being transmitted as it's been used to enter data into a database.
Assuming that you have not performed any port forwarding from the internet to the device that you are running your Django server on you are safe. It will only expose the Django web service and realistically locally in your house hopefully you don't have anyone out to get you.
If you only want to be able to access your Django development server locally you can change the command to: python3 manage.py runserver 127.0.0.1:8000 no one will be able to access it unless they are coming from the same machine.
I have finished coding a Django App. In that app I have created two models in order to record some project information. Also I am showing project locations with markers on a map (OpenStreetMap) by using leaflet.js.
I will use this app only by starting an offline server like "python manage.py runserver". I am using "Firefox" to display the django app.
I really wonder if somehow the information that I keep in my django models or the markers on the OpenStreetMap is somehow reachable by others via on Firefox or leaflet.
Thank you very much in advance.
If you are in the same wi-fi network you can run python manage.py runserver 0.0.0.0:8000 and then your application will be visible for everybody by typing http://your-pc-up:8000
If you want to make it public you have to buy domain (or register free domain) and put it in your vpc / free hosting. There are plenty of tutorial out there which show how to host an application.
This tutorial is really easy and straight forward: http://michal.karzynski.pl/blog/2013/06/09/django-nginx-gunicorn-virtualenv-supervisor/
You can use ngrok service which gives you domain such as https://c2757c5f.ngrok.io and other users can visit it by accessing this url. In addition, this url can be visited from anywhere!
See more details by visiting here
If you want other users can visit you website from you local server, then you can run manage.py runserver 0.0.0.0:8000. Your app is visible to other users on same network by accessing this http://your-ip:8000/
You could know you ip by using ifconfig command on linux or ubuntu
I was wondering how I could let Chrome connect to my network. I am using a website called Codeanywhere.com and I was using a Django container. I used the built-in terminal and installed Python 3.4 and Django 10. I created a project and ran the server, and it said it had created one at this ip: http://127.0.0.1:8000/. However, whenever I try to access it, it the site can't be reached. If it helps, I am using a Chromebook Thinkpad, and it is a school computer. They do block things with Lightspeed Systems and they have a lot of blacklisting things going on. I am trying to learn Django for a project. Below is a screenshot of the screen when I try to access the server.
My screenshot of the error screen.
I can't embed my image yet, I don't have 10 reputation points :/ It's a link instead.
Mistake #1
The server isn't located on your local host, so you need to go to the provided server. for example, when I opened a project I got this instruction:
To access your application over HTTPS, make sure your application is running on port 3000 and use the following link:
https://mysite-{username}551936.codeanyapp.com
Mistake #2
you should run the server with a specified ip commend - and use 0.0.0.0:3000 instead of the usual localhost, like so:
python manage.py runserver 0.0.0.0:3000
In addition, I would reccomend you to read the "mysite Container" file which explains everything about the setup in detail.
In debugging mode, I can run django web that can be accessed by public (inside LAN) with:
python manage.py runserver 0.0.0.0:8000
So, is it possible to run it directly on port 80 (maybe with a domain) like normally webserver does? If yes, is it a bad idea? I mean, is it better to use apache with mod_wsgi?
Its possible, but its a really bad idea because the default server that django ships with does not support multiproccessing etc, and is meant solely for development.
As the documentation notes:
Now’s a good time to note: DON’T use this server in anything resembling a production environment. It’s intended only for use while developing. (We’re in the business of making Web frameworks, not Web servers.)
As for the choice of web server, do have a look at the django book to get more ideas around how to go ahead with it.
It is possible. You can do it like this:
python manage.py runserver yourdomain.com:80
Whether it is a bad idea, it may depend on your use case. Generally I would recommend using e.g. apache or nginx for long-term running production environment though. It will surely perform better.
If you are needing to more easily debug an issue specifically when using similar environment to deployment, but still have it run on port 80, then presuming the system Apache is shut down and so not using port 80 at the time, then have a look at mod_wsgi-express.
https://pypi.python.org/pypi/mod_wsgi
For information on better integrating mod_wsgi-express with Django and using it for debugging see:
http://blog.dscpl.com.au/2015/04/introducing-modwsgi-express.html
http://blog.dscpl.com.au/2015/04/using-modwsgi-express-with-django.html
http://blog.dscpl.com.au/2015/04/integrating-modwsgi-express-as-django.html
http://blog.dscpl.com.au/2015/05/using-modwsgi-express-as-development.html
Sound like two questions there.
Is it possible? Yes (see #geckon's answer).
Is it wise to run a debug-friendly lightweight development server in production? : No
But luckily there's plenty of official documentation on running Apache with mod_wsgi, so that shouldn't be too hard.
I use Django for my website and I want to know whether there is a work around for testing secure pages in Development server. As a temporary workaround, I wont use HTTP to check the webpages in dev server, which I think is not a correct way? What do you think?
You might consider mod_wsgi, since it can be used for development, testing, and deployment. mod_wsgi can be configured to detect any changes to you make to your Python code and automatically restart, same as the development server.
I tend to do most of my development on my local machine, but use an actual reference implementation server for testing. It's running mod_wsgi under apache, with a self-signed certificate. A recent detailed article by Graham Dumpleton is available here:
http://blog.dscpl.com.au/2008/12/using-modwsgi-when-developing-django.html
This looks helpful -- using stunnel to route HTTPS requests to django dev server.
The Django development server is very basic and intended for local testing only. It does not support ssl/https. You'll have to run it using Apache, NGINX, or some other web server that supports SSL in order to test.
You can now use FakeSSLMiddleware