Search This Blog

Thursday, October 17, 2024

How to run Django Applications in Https directly - SSL - Openssl or CA certificate

 Here is the simple steps.

1. Either you can use mkcert or openssl.


2. openssl req -newkey rsa:4096 \

            -x509 \

            -sha256 \

            -days 365 \

            -nodes \

            -out ordersbts.crt \

            -keyout ordersbts.key \

            -subj "/C=SI/ST=KARNATAKA/L=BANGALORE/O=ArsenaiT/OU=ITServices/CN=ourapp.arsenalit.com"


3. Configuring Django server to work with HTTPS

The default Django manage.py runserver command doesn't support SSL; therefore, we need to use the alternative manage.py runserver_plus command, which is part of the excellent Django Extensions package.

Run the following command to install Django extensions alongwith the Wekzeug server:

pip install django-extensions Werkzeug

The runserver_plus command requires installation of the Werkzeug server, which is better known in the world of the Python Framework Flask.


Next, open the settings.py file in your code editor and add django_extensions to the INSTALLED_APPS list:


settings.py

NSTALLED_APPS = [

    # other apps

    "django_extensions",

]

Finally, start the local development server in HTTPS mode by running the command:

nohup python3.9 manage.py runserver_plus --cert-file httpskeys/myapp.crt --key-file httpskeys/myapp.key 0.0.0.0:443 &


And that's it; you should now see the local development server running at the default https://localhost:443 address.


If any error comes, 

1. Delete your virtual environment folder and Recreate it. 

       sudo rm -r venv3.9

        python3.9 -m venv env3.9

       deactivate

       source env3.9/bin/activate


2. Run your libraries with pip install -r requirements.txt

3. excute python3.9 manage.py [above command]


ENJOY


For mkcert use this following link https://timonweb.com/django/https-django-development-server-ssl-certificate/


No comments:

Hit Counter


View My Stats