After we installed the Django, we use the command:
python manage.py runserver
we can run a server, but I don't know the server is which server, and I searched the django directory, find the server is not in the directory:
aircraftdeMacBook-Pro:Django-1.11.2-py2.7.egg ldl$ cd django/
aircraftdeMacBook-Pro:django ldl$ ls
__init__.py bin dispatch shortcuts.pyc utils
__init__.pyc conf forms template views
__main__.py contrib http templatetags
__main__.pyc core middleware test
apps db shortcuts.py urls
So, I have two questions:
The server is which web-server, and how can I find its location?
If we finish the application, if we use the web-server as the python-web's web-server(means why not apache or nginx)?
The port default is 8000, how to change to the 80?
1) Django provides a default wsgi server as #sach20 mentioned.
2) The django server should be used for development. I personally use nginx and gunicorn to run my server. You can find a tutorial on how to set on up here:
Tutorial
3) You can run:
python manage.py runserver 0.0.0.0:80
You can substitute 80 with any port you want to use.
Django runserver is a local dev server, should not be used in production... APACHE AND NGINX are different things.
Django provides a simple WSGI server as a dev server.
Also id guess you have not looked inside the django docs because what you are looking for is right here
Examples of using different ports and addresses¶
Port 8000 on IP address 127.0.0.1:
django-admin runserver Port 8000 on IP address 1.2.3.4:
django-admin runserver 1.2.3.4:8000 Port 7000 on IP address 127.0.0.1:
django-admin runserver 7000
Django provides a default wsgi development server
Related
I set the bellow code in the wsgi.py,:
eventlet.wsgi.server(eventlet.listen(('', 8000)), application)
if I use the:
python3 manage.py runserver 0.0.0.0:8001
it will ignore the 8001 port of python3 manage.py runserver 0.0.0.0:8001?
because the logs are:
$ python manage.py runserver 0.0.0.0:8001
Performing system checks...
System check identified no issues (0 silenced).
May 09, 2018 - 10:48:35
Django version 1.11.5, using settings 'Qiyun02.settings'
Starting development server at http://0.0.0.0:8001/
Quit the server with CONTROL-C.
(4516) wsgi starting up on http://0.0.0.0:8000 # you see this is using 8000
If this line settings:
eventlet.wsgi.server(eventlet.listen(('', 8000)), application)
('', 8000) means : 0.0.0.0:8000?
There is a simple profile of evenlet wsgi, in your wsgi.py you use the eventlet wsgi as the application's wsgi.
eventlet.wsgi.server(eventlet.listen(('', 8000)), application)
the eventlet.listen() is a param of eventlet.wsgi.server(), and the eventlet.listen() means listen which address and port.
the ('', 8000) combine the address and port. if we do not set the first param, it will be default 0.0.0.0.
if we set the localhost it will be look back address 127.0.0.1.
and we also can set a IP address of our computer's.
We can use ifconfig -a to list the available IP addresses of our *nix computer.
use ipconfig -a to list the Windows's.
I have this ProcFile file following this guidelines for django app deployment on section Build your app and run it locally in order to test it locally you have to run this command.
web: python manage.py runserver 0.0.0.0:$PORT
Then running heroku local or heroku local web got me into this error:
CommandError: "0.0.0.0:$PORT" is not a valid port number or address:port pair.
You must not use runserver in production. Use gunicorn as the docs and comments suggest.
For local:
If you follow this official heroku tutorial and you are running it on Window platform locally, instead of $PORT, you have to use %PORT% at your Procfile.windows:
web: python manage.py runserver 0.0.0.0:%PORT%
since window does not interpret $PORT expression which only applicable in Unix shells.
If one using waitress as WSGI and wanna run it locally on Window platform, your Procfile should looks like this:
web: waitress-serve --port=%PORT% wsgi:your_app
For real online deployment:
simply include gunicorn package in requirementx.txt and your Procfile should be in this way:
web: gunicorn wsgi:your_app
If you are using waitress, you need to change back to $PORT, and set it in this way instead of fixed port number since Heroku assigns port to your app dynamically. Also, do make sure the host is set to 0.0.0.0 so your app is available externally.
For a django project in heroku you must have a Procfile like this:
web: gunicorn yourapp.wsgi
The filename must be Procfile, and not ProcFile
If you want to run into development you can either $ python manage.py runserver in your shell (heroku independent) or run $ heroku local with a valid production Procfile
How can I set an alias in Django Server, for example :
http://10.179.146.45:8080/en/
to be
http://my_name/en/
I run this server without apache and without mod_wsgi.
You can specify the host name and port for the Django development server.
$ manage.py runserver my_name:8080
It's kinda weird I cannot access django from localhost but I able to access it from local IP.
python manage.py runserver 0.0.0.0:8000
then when I try to access from
My host file
127.0.0.1 lmlicenses.wip4.adobe.com
127.0.0.1 lm.licenses.adobe.com
127.0.0.1 gc.kis.scr.kaspersky-labs.com ff.kis.scr.kaspersky-labs.com ie.kis.scr.kaspersky-labs.com
0.0.0.0 gc.kis.scr.kaspersky-labs.com ff.kis.scr.kaspersky-labs.com ie.kis.scr.kaspersky-labs.com
I'm guessing something wrong with windows firewall or kaspersky,but I don't know what to do.
I've add exception to port 8000 and python.exe too
I cannot access localhost:8000 from my browser if I run python manage.py runserver
I don't know why that command cannot work in my laptop, but in my pc it just works.
====
ok, so my solution now is to use ipv6 and port 8000 which is
python manage.py runserver [::]:8000
Just try http://0.0.0.0:8000 instead of localhost:8000
Default localhost value is http://127.0.0.1
If you see the runerver result you have :
starting developement server at http://0.0.0.0:8000
Because you told that django server start at http://0.0.0.0:8000 when you run this command :
python manage.py runserver 0.0.0.0:8000
I'm also beginner to django, but I needed following things in order to run the server:
In settings.py, added ALLOWED_HOSTS as
ALLOWED_HOSTS = [
'elearning.com'
]
where elearning.com is my hostname. You can have multiple hosts separated with comma.
Used following command to run the server:
python manage.py runserver [::]:8000 or python manage.py runserver 0.0.0.0:8000 or python manage.py runserver 0:8000.
It will now listen to all interfaces. Read Django doc here.
Browsed to given hostname. In my case, it is http://elearning.com:8000/
I tried writing IP in ALLOWED_HOSTS but it didn't work, I could not open http://192.168.x.x:8000 in browser. Can anyone please correct me?
simply execute
python manage.py runserver
automatically you can access by localhost and for the extern access you could have access if not are it's locked the port 8000, for access to django admin use the next url:
http://127.0.0.1:8000/admin/
How your host file end up like this ?? . Can you test something.
# Copyright (c) 1993-2009 Microsoft Corp.
#
# This is a sample HOSTS file used by Microsoft TCP/IP for Windows.
#
# This file contains the mappings of IP addresses to host names. Each
# entry should be kept on an individual line. The IP address should
# be placed in the first column followed by the corresponding host name.
# The IP address and the host name should be separated by at least one
# space.
#
# Additionally, comments (such as these) may be inserted on individual
# lines or following the machine name denoted by a '#' symbol.
#
# For example:
#
# 102.54.94.97 rhino.acme.com # source server
# 38.25.63.10 x.acme.com # x client host
# localhost name resolution is handled within DNS itself.
# 127.0.0.1 localhost
# ::1 localhost
My host file see everything is commented out. Can you do the same with your hosts file and give it a Try .. .
In the settings.py file in your project folder,
add '0.0.0.0' to the allowed host list.
Then save the file and run the command.Guess will work.
user manager.py runserver my flask webframework can start on http://127.0.0.1:5000 but it can not access on other computer in network.
so i need use an open IP in network.
although i use bellow command:
manage.py runserver 192.168.49.25:8000
it can not run and give a error info:
manage.py: error: unrecognized arguments: 192.168.49.25:8000
I don't known what's wrong with it??
If you want to use Flask-Script (python manage.py runserver) to run your Flask Application you can use the parameter --host to run it on a public IP.
python manage.py runserver --host 0.0.0.0
see also: https://flask-runner.readthedocs.org/en/latest/
Read the documentation:
Externally Visible Server If you run the server you will notice that
the server is only accessible from your own computer, not from any
other in the network. This is the default because in debugging mode a
user of the application can execute arbitrary Python code on your
computer.
If you have debug disabled or trust the users on your network, you can
make the server publicly available simply by changing the call of the
run() method to look like this:
app.run(host='0.0.0.0') This tells your operating system to listen on
all public IPs.
If you're already using Flask-Script then you have a way to get your host defined in your code.
from yourapp import create_app
from flask_script import Manager, Server
from yourapp import config
app = create_app(config.DevelopmentConfig)
manager = Manager(app)
manager.add_command("runserver", Server(host=app.config['HOST'], port=app.config['PORT']))
if __name__ == '__main__':
manager.run()
now the server host and port will come from config