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
Related
i have a react frontend imported inside a django backend. communication between the two is done through django-rest-framework. on the react's side, fetching is done through relative paths therefore in my package.json i have added the line:
"proxy": "http://127.0.0.1:8000",
django is hosting react-app locally without problems when i run: python3 manage.py runserver.
on the remote i am trying to use nginx with gunicorn to deploy this app on aws ubuntu instance and run into the problem:
first, i'm running python3 manage.py collectstatic
later, i'm pointing nginx to that static_files for the index.html
success! nginx serves react static files
use gunicorn myapp.wsgi -b 127.0.0.1:8000 to run django
problem! nginx served react files do not fetch anything. fetch does not call for this local path but instead calls public ip of aws instance. also, i cannot simulate get/post requests to the django backend because i think nginx "covers" django's gunicorn generated paths.
please tell how can i connect nginx-served react frontedn to gunicorn run django
my nginx sites-enabled/example
server {
listen 80 default_server;
listen [::]:80 default_server;
root /home/ubuntu/fandigger/frontend/build/;
server_name public_ip_without_port;
location / {
try_files $uri $uri/ =404;
}
}
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.
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
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