User Tools

Site Tools


python:dev-mode

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
python:dev-mode [2024/10/02 06:38] kirtisinghpython:dev-mode [2024/10/02 07:52] (current) kirtisingh
Line 77: Line 77:
 <code> <code>
 gunicorn -b 0.0.0.0:8000 -w 4 --forwarded-allow-ips='172.16.26.1' hello:app & gunicorn -b 0.0.0.0:8000 -w 4 --forwarded-allow-ips='172.16.26.1' hello:app &
 +</code>
 +
 +To exit virtual environment use the command
 +<code>
 +deactivate
 </code> </code>
  
Line 91: Line 96:
  
 <code> <code>
-pip install flask+pip install django
 pip install gunicorn pip install gunicorn
 </code> </code>
  
-You you can upload/write your Flask app and fire it up using gunicorn, but here I will showcase an example using the hello world app - refer https://flask.palletsprojects.com/en/2.3.x/quickstart+Here we can refer to https://docs.djangoproject.com/en/5.1/intro/tutorial01/ to run a hello world Django application
  
-Below code is saved to hello.py+<code
 +django-admin startproject mysite 
 +cd mysite 
 +</code> 
 + 
 +When you change into //mysite// folder, it contains //manage.py// along with a //mysite// child folder 
 + 
 +W.r.t. Django, please refer to these important links \\ 
 +* https://docs.djangoproject.com/en/1.10/ref/settings/#allowed-hosts - Please add your VHost name as mentioned in the linked article \\ 
 +* https://docs.djangoproject.com/en/3.0/ref/settings/#secure-proxy-ssl-header - Tt concerns the prefixing of http or https to your URLs/Assets 
 + 
 +Now to fire our Django app, we use gunicorn 
  
 <code> <code>
-from flask import Flask+gunicorn -b 0.0.0.0:8000 -w 4 --forwarded-allow-ips='172.16.26.1' mysite.wsgi 
 +</code>
  
-app = Flask(__name__)+To run it in background, we append & to the above command
  
-@app.route("/") +<code> 
-def hello_world(): +gunicorn -b 0.0.0.0:8000 -w 4 --forwarded-allow-ips='172.16.26.1' mysite.wsgi & 
-    return "<p>Hello, World!</p>"+</code> 
 + 
 + 
 +To exit virtual environment use the command 
 +<code> 
 +deactivate 
 +</code> 
 + 
 + 
 +**Generic Python App** 
 + 
 +<code> 
 +mkdir generic-project 
 +cd geneic-project 
 +python3 -m venv .venv 
 +source .venv/bin/activate 
 +</code> 
 + 
 +Running the last command with activate the virtual environment, proceeding further 
 + 
 +<code> 
 +pip install gunicorn 
 +</code> 
 + 
 +Here is a small hello world example of our generic app 
 + 
 +Below code is saved to hello.py 
 + 
 +<code> 
 +def app(environ, start_response): 
 +    data = b"Hello, World!\n" 
 +    start_response("200 OK", [ 
 +        ("Content-Type", "text/plain"), 
 +        ("Content-Length", str(len(data))) 
 +    ]) 
 +    return iter([data])
 </code> </code>
  
Line 117: Line 169:
 To run it in background, we append & to the above command To run it in background, we append & to the above command
  
-To exit virtual environment use the command 
 <code> <code>
-deactivate+gunicorn -b 0.0.0.0:8000 -w 4 --forwarded-allow-ips='172.16.26.1' hello:app &
 </code> </code>
  
 +To exit virtual environment use the command
 <code> <code>
-gunicorn -b 0.0.0.0:8000 -w 4 --forwarded-allow-ips='172.16.26.1' hello:app &+deactivate
 </code> </code>
 +\\
 +**With this our SSH Console aspect of our python project is covered. Now we will link our app to our VHost/Website URL**
 +
 +
 +**Step 6 :** Log into N99panel and click on 'Python'
 +
 +{{:python:screenshot_capture_-_2024-10-01_-_06-05-15.png?direct&400|}} 
  
  
 +**Step 7 :** Now click on 'Python Apps via SSH'
  
 +{{:python:screenshot_capture_-_2024-10-01_-_06-06-40.png?direct&400|}}
  
 +**Step 8 :** Now further click on 'Map a Python Dev Port'
  
 +{{:python:screenshot_capture_-_2024-10-01_-_06-08-21.png?direct&400|}}
  
 +**Step 9 :** Fill the form with the requisite details
  
 +{{:python:screenshot_capture_-_2024-10-01_-_06-33-16.png?direct&600|}}
  
 +With these above mentioned steps, you can showcase your python apps to the world very easily.
  
python/dev-mode.1727851101.txt.gz · Last modified: 2024/10/02 06:38 by kirtisingh

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki