R
R
RenjiYamato2018-01-29 00:52:31
Apache HTTP Server
RenjiYamato, 2018-01-29 00:52:31

How to create a flask app on centos7?

I apologize in advance for such a stupid question
. Here is the complete procedure.
1. Install Python, Flask, mod_wsgi

yum install python34 python34-devel python34-pip
pip3 install Flask
yum install mod_wsgi

2. In /var/www/html I create the flask_dev directory and the hello.py and hello.wsgi
hello.py files in it:
#! usr/bin/python
from flask import Flask
app = Flask(__name__)
@app.route("/")
def hello1():
return "Hello World!"
if __name__ == "__main__":
app.run()

hello.wsgi:
import sys
sys.path.insert(0, '/var/www/html/flask_dev')
from hello import app as application

3. I replace the contents of /etc/httpd/conf.d/<server address>.conf with
<VirtualHost *80>
ServerName <адрес сервера>

WSGIScriptAlias / /var/www/html/flask_dev/hello.wsgi
WSGIScriptReloading On
<Directory /var/www/html/flask_dev>
Order deny,allow
Allow from all
</Directory>
</VirtualHost>

4. I create redirects for port 80 through the control panel
5. I restart Apache
systemctl restart httpd
6. I open the server address in the browser
In response:
Index of /

Name	Last modified	Size	Description
flask_dev/	2018-01-28 01:14	-

5a6e45bdb0905756232393.jpeg
What is done wrong?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
J
John Doe, 2018-02-03
@rabbit418

1. sudo yum install epel-release
2. sudo yum install python-pip python-devel gcc nginx
3. sudo pip install virtualenv
4. mkdir ~/myproject
5. cd ~/myproject
6. virtualenv myprojectenv
7. source myprojectenv/bin/ activate
8. pip install gunicorn flask
9. vim ~/myproject/myproject.py

from flask import Flask
application = Flask(__name__)

@application.route("/")
def hello():
    return "<h1 style='color:blue'>Hello There!</h1>"

if __name__ == "__main__":
    application.run(host='0.0.0.0')

10.python myproject.py 11.open
localhost :5000

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question