python:django-prod-mode
Differences
This shows you the differences between two versions of the page.
| Next revision | Previous revision | ||
| python:django-prod-mode [2024/10/06 09:59] – created kirtisingh | python:django-prod-mode [2024/10/06 10:09] (current) – kirtisingh | ||
|---|---|---|---|
| Line 5: | Line 5: | ||
| Once you have tested you app in development mode, we can then undertake following steps to run our Django app in production mode | Once you have tested you app in development mode, we can then undertake following steps to run our Django app in production mode | ||
| - | **Step 1 :** Log into N99panel. From under N99panel dashboard, | + | **Step 1 :** Log into N99panel |
| - | {{:gen:list-users.png? | + | {{:python:screenshot_capture_-_2024-10-01_-_06-05-15.png? |
| - | \\ | + | |
| - | **Step 2 :** You will see the list of all the users. Please click ' | ||
| - | {{:gen:click-manage-sshd.png? | + | **Step 2 :** Now click on ' |
| - | \\ | + | |
| - | **Step 3 :** Now choose 'Full SSHD mode with Python' | + | {{:python:pythin-prod-s2.png? |
| - | + | ||
| - | {{:python:screenshot_capture_-_2024-10-01_-_22-06-14.png? | + | |
| - | \\ | + | |
| - | When you click ' | + | |
| - | + | ||
| - | **Step 4 :** SSH using to the VPS using the above user's credentials | + | |
| - | + | ||
| - | **Step 5 :** Change over to directory/ | + | |
| - | + | ||
| - | Assuming you are / | + | |
| - | + | ||
| - | < | + | |
| - | mkdir python_apps | + | |
| - | </ | + | |
| - | + | ||
| - | Now change into python_apps folder | + | |
| - | + | ||
| - | < | + | |
| - | cd python_apps | + | |
| - | </ | + | |
| - | + | ||
| - | **Step 6 :** From within this folder add/create your python project as you would normally do. Below we illustrate with specific examples for Flask, Django and Generic modes | + | |
| - | + | ||
| - | **Flask** | + | |
| - | + | ||
| - | < | + | |
| - | mkdir flask-project | + | |
| - | cd flask-project | + | |
| - | python3 -m venv .venv | + | |
| - | source .venv/ | + | |
| - | </ | + | |
| - | + | ||
| - | Running the last command with activate the virtual environment, | + | |
| - | + | ||
| - | < | + | |
| - | pip install flask | + | |
| - | pip install gunicorn | + | |
| - | </ | + | |
| - | + | ||
| - | You you can upload/ | + | |
| - | + | ||
| - | Below code is saved to hello.py | + | |
| - | + | ||
| - | < | + | |
| - | from flask import Flask | + | |
| - | + | ||
| - | app = Flask(__name__) | + | |
| - | + | ||
| - | @app.route("/" | + | |
| - | def hello_world(): | + | |
| - | return "< | + | |
| - | </ | + | |
| - | + | ||
| - | Now to fire our flash app, we use gunicorn | + | |
| - | + | ||
| - | < | + | |
| - | gunicorn -b 0.0.0.0: | + | |
| - | </ | + | |
| - | + | ||
| - | To run it in background, we append & to the above command | + | |
| - | + | ||
| - | < | + | |
| - | gunicorn -b 0.0.0.0: | + | |
| - | </ | + | |
| - | + | ||
| - | To exit virtual environment use the command | + | |
| - | < | + | |
| - | deactivate | + | |
| - | </ | + | |
| - | + | ||
| - | **Django** | + | |
| - | + | ||
| - | < | + | |
| - | mkdir django-project | + | |
| - | cd django-project | + | |
| - | python3 -m venv .venv | + | |
| - | source .venv/ | + | |
| - | </ | + | |
| - | + | ||
| - | Running the last command with activate the virtual environment, | + | |
| - | + | ||
| - | < | + | |
| - | pip install django | + | |
| - | pip install gunicorn | + | |
| - | </ | + | |
| - | + | ||
| - | Here we can refer to https:// | + | |
| - | + | ||
| - | < | + | |
| - | django-admin startproject mysite | + | |
| - | cd mysite | + | |
| - | </ | + | |
| - | + | ||
| - | When you change into //mysite// folder, it contains // | + | |
| - | + | ||
| - | W.r.t. Django, please refer to these important links \\ | + | |
| - | * https:// | + | |
| - | * https:// | + | |
| - | + | ||
| - | Now to fire our Django app, we use gunicorn | + | |
| - | + | ||
| - | < | + | |
| - | gunicorn -b 0.0.0.0: | + | |
| - | </ | + | |
| - | + | ||
| - | To run it in background, we append & to the above command | + | |
| - | + | ||
| - | < | + | |
| - | gunicorn -b 0.0.0.0: | + | |
| - | </ | + | |
| - | + | ||
| - | + | ||
| - | To exit virtual environment use the command | + | |
| - | < | + | |
| - | deactivate | + | |
| - | </ | + | |
| - | + | ||
| - | + | ||
| - | **Generic Python App** | + | |
| - | + | ||
| - | < | + | |
| - | mkdir generic-project | + | |
| - | cd geneic-project | + | |
| - | python3 -m venv .venv | + | |
| - | source .venv/ | + | |
| - | </ | + | |
| - | + | ||
| - | Running the last command with activate the virtual environment, | + | |
| - | + | ||
| - | < | + | |
| - | pip install gunicorn | + | |
| - | </ | + | |
| - | + | ||
| - | Here is a small hello world example of our generic app | + | |
| - | + | ||
| - | Below code is saved to hello.py | + | |
| - | + | ||
| - | < | + | |
| - | def app(environ, | + | |
| - | data = b" | + | |
| - | start_response(" | + | |
| - | (" | + | |
| - | (" | + | |
| - | ]) | + | |
| - | return iter([data]) | + | |
| - | </ | + | |
| - | + | ||
| - | Now to fire our flash app, we use gunicorn | + | |
| - | + | ||
| - | < | + | |
| - | gunicorn -b 0.0.0.0: | + | |
| - | </ | + | |
| - | + | ||
| - | To run it in background, we append & to the above command | + | |
| - | + | ||
| - | < | + | |
| - | gunicorn -b 0.0.0.0: | + | |
| - | </ | + | |
| - | + | ||
| - | To exit virtual environment use the command | + | |
| - | < | + | |
| - | deactivate | + | |
| - | </ | + | |
| - | \\ | + | |
| - | **With this our SSH Console aspect of our python project is covered. Now we will link our app to our VHost/ | + | |
| - | + | ||
| - | + | ||
| - | **Step 6 :** Log into N99panel and click on ' | + | |
| - | + | ||
| - | {{: | + | |
| - | **Step | + | **Step |
| - | {{:python:screenshot_capture_-_2024-10-01_-_06-06-40.png? | + | {{:python:pythin-prod-s3.png? |
| - | **Step 8 :** Now further click on 'Map a Python Dev Port' | ||
| - | {{:python: | + | **Step 4 :** Then enter details of your Django App as explained below |
| - | **Step 9 :** Fill the form with the requisite details | + | {{:python: |
| - | {{: | ||
| - | With these above mentioned steps, you can showcase | + | With these above mentioned steps, you can run your Django app in production mode. |
python/django-prod-mode.1728208791.txt.gz · Last modified: 2024/10/06 09:59 by kirtisingh
