-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathflask.txt
94 lines (67 loc) · 1.82 KB
/
flask.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
Flask
=====
Steven K. Baum
v0.1, 2016-12-14
:doctype: book
:toc:
:icons:
:numbered!:
[preface]
Installation
------------
Install Flask via:
-----
pip install Flask
-----
This may vary depending on which Python distribution the Flask distribution
is installed in. In the example below it was installed in the Python 3 distribution
on barataria and thus installed via "pip3 install Flask". It is already installed there
so this can be skipped.
Running Flask Using mod_wsgi
----------------------------
Creating the Files in the HTTP HTML Directory
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Create the file hello.wsgi with the contents:
-----
import sys
from hello import app as application
-----
This is the file that points the WSGI machinery to whatever Python
file contains the substantial code. In this case the "hello" indicates
that it should look for the file "hello.py" in the same directory.
Create the file hello.py with the contents:
-----
#!/usr/bin/python3
from flask import Flask
app = Flask(__name__)
@app.route("/")
def hello():
return "Hello World!"
if __name__ == "__main__":
app.run()
-----
Note that the first line in this file will change if your Python binary
directory is elsewhere. This is the file into which more complicated things than
"Hello World!" will be placed.
Put these files in the directory:
-----
/var/www/html/flask
-----
Configuring Apache
~~~~~~~~~~~~~~~~~~
Edit the httpd.conf file and add:
-----
Alias /flask /var/www/html/flask/hello.wsgi
WSGIPythonPath /var/www/html/flask
<Directory /var/www/html/flask>
SetHandler wsgi-script
Options ExecCGI
</Directory>
-----
Restart Apache and point your browser to:
-----
http://pong.tamu.edu/flask
-----
to receive the "Hello World!" message.
The Apache server should be restarted whenever you create a new
alias for a flask program.