-3

How do i run django application without port number: i had tried Django: Run django app on server without port? but didn't work.

3 Answers3

0

Web services must bind a port on a interface of the system. So, you should specify a port number to run your Django application. The default port number for HTTP is 80, for HTTPS 443. But you can use a custom port between [1-65535]: For example;

python manage.py runserver 7000
M Burak
  • 36
  • 3
  • Thank you @M Burak, How can i run the Docker Django app which is configured as dev in the default port 80 with out webserver, In my local dev when i run "python manage.py runserver 80" i can run the application without port number [127.0.0.1], How can i do the same thing in Docker? " web: build: . command: sh -c "/etc/init.d/cron start && python manage.py makemigrations && python manage.py migrate && python manage.py crontab add && exec python manage.py runserver 0.0.0.0:8000" ports: - "8000:8000" depends_on: - db" – Peter Nanii Nov 18 '21 at 03:19
0

You may try the following:

python manage.py runserver 80

or if you don't have permissions (assuming you are using Linux):

sudo python manage.py runserver 80

Then, you can access your application: http://localhost/

Ahmed Ablak
  • 718
  • 3
  • 14
0

In general, web services need a port to run. If the port used is default http (80) or https (443) port, modern web browsers hide it from seeing in the address bar.

In a development server, you can hide the port(because you don't want to see it anymore) by assigning it to port 80 if it is not used by any other web service in the system(otherwise django will complain):

python manage.py runserver 80

In a production server, you need to use servers like Gunicorn to run your django app in the backend and a web server like Nginx or Apache to serve your backend to external world. In that case, since web servers use http/https ports, no ports will be visible in the browser.

  • Thank you @Basil C Sunny, How can i run the Docker Django app which is configured as dev in the default port 80 with out webserver, In my local dev when i run "python manage.py runserver 80" i can run the application without port number [127.0.0.1], How can i do the same thing in Docker? " web: build: . command: sh -c "/etc/init.d/cron start && python manage.py makemigrations && python manage.py migrate && python manage.py crontab add && exec python manage.py runserver 0.0.0.0:8000" ports: - "8000:8000" depends_on: - db" – Peter Nanii Nov 18 '21 at 03:17
  • with port mapping like ports: -"80:8000" – Basil C Sunny Nov 18 '21 at 06:11