I would like to make the website built on Django server (hosted on AWS EC2 instance) as public. As a first step, I would want to update the default port from 0.0.0.0:8000 to 0.0.0.0:80 or 0.0.0.0.
Every time I change port and run server, it gives me the below error:
System check identified no issues (0 silenced).
October 08, 2022 - 15:55:12
Django version 3.2.12, using settings 'config.settings'
Starting development server at http://0.0.0.0:80/
Quit the server with CONTROL-C.
Error: You don't have permission to access that port.
If I use sudo or access it as root user, it gives me the following error:
(venv) [ec2-user@ip-172-31-19-84 config]$ sudo python3 manage.py runserver 0.0.0.0:80
Traceback (most recent call last):
File "manage.py", line 11, in main
from django.core.management import execute_from_command_line
ModuleNotFoundError: No module named 'django'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "manage.py", line 22, in <module>
main()
File "manage.py", line 14, in main
"Couldn't import Django. Are you sure it's installed and "
ImportError: Couldn't import Django. Are you sure it's installed and available on your PYTHONPATH environment variable? Did you forget to activate a virtual environment?
And as root user:
(venv) [root@ip-172-31-19-84 config]# python3 manage.py runserver 0.0.0.0:80
Traceback (most recent call last):
File "manage.py", line 11, in main
from django.core.management import execute_from_command_line
ModuleNotFoundError: No module named 'django'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "manage.py", line 22, in <module>
main()
File "manage.py", line 14, in main
"Couldn't import Django. Are you sure it's installed and "
ImportError: Couldn't import Django. Are you sure it's installed and available on your PYTHONPATH environment variable? Did you forget to activate a virtual environment?
Here's my manage.py file:
#!/usr/bin/env python
"""Django's command-line utility for administrative tasks."""
import os
import sys
def main():
"""Run administrative tasks."""
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'config.settings')
try:
from django.core.management import execute_from_command_line
except ImportError as exc:
raise ImportError(
"Couldn't import Django. Are you sure it's installed and "
"available on your PYTHONPATH environment variable? Did you "
"forget to activate a virtual environment?"
)
execute_from_command_line(sys.argv)
if __name__ == '__main__':
main()