Flask: Difference between revisions
Jump to navigation
Jump to search
(→Flask) |
(→SITE) |
||
Line 68: | Line 68: | ||
===SITE=== | ===SITE=== | ||
<code>vim /etc/apache2/sites-available/000-default.conf</code> | <code>vim /etc/apache2/sites-available/000-default.conf</code> | ||
<source lang="apache" start="15" line> | <source lang="apache" highlight="1,2,7,8" start="15" line> | ||
WSGIScriptAlias /rest "/var/www/flask/RestApi/RestApi.wsgi" | WSGIScriptAlias /rest "/var/www/flask/RestApi/RestApi.wsgi" | ||
<Directory "/var/www/flask/RestApi/RestApi"> | <Directory "/var/www/flask/RestApi/RestApi"> |
Revision as of 12:08, 24 May 2020
Python3
apt install python3.8
pip3 install virtualenv
cd /var/www/flask/RestApi/RestApi/
virtualenv venv
source venv/bin/activate
pip install Flask
deactivate
Flask
mkdir -p /var/www/flask/RestApi/RestApi/{static,templates}
cat > /var/www/flask/RestApi/RestApi/__init__.py << EOF
from flask import Flask
app = Flask(__name__)
@app.route("/")
def hello():
return "Hello, Bangladesh!"
if __name__ == "__main__":
app.run()
EOF
WSGI3
cd /var/www/flask/RestApi/
cat > /var/www/flask/RestApi/RestApi.wsgi << EOF
#!/usr/bin/python
activate_this = '/var/www/flask/RestApi/RestApi/venv/bin/activate_this.py'
with open(activate_this) as file_:
exec(file_.read(), dict(__file__=activate_this))
import sys
import logging
logging.basicConfig(stream=sys.stderr)
sys.path.insert(0,"/var/www/flask/RestApi/")
from RestApi import app as application
application.secret_key = 'Add your secret key'
EOF
Apache3
WSGI3
apt install apache2
systemctl restart apache2
apt install libapache2-mod-wsgi python-dev
a2enmod wsgi
a2dismod wsgi
apt remove libapache2-mod-wsgi python-dev
apt install libapache2-mod-wsgi-py3 python3-dev
a2enmod wsgi
apache2ctl -t
systemctl enable apache2
systemctl restart apache2
SITE
vim /etc/apache2/sites-available/000-default.conf
WSGIScriptAlias /rest "/var/www/flask/RestApi/RestApi.wsgi"
<Directory "/var/www/flask/RestApi/RestApi">
Order Allow,Deny
Allow from all
</Directory>
Alias /rest/static "/var/www/flask/RestApi/RestApi/static/"
<Directory "/var/www/flask/RestApi/RestApi/static">
Order Allow,Deny
Allow from all
</Directory>