I'm just started to learn back-end web development using Python and Flask framework.
My first application is the simplest one and it returns "Hello World!" when the user send a request for website's homepage.
Below, you can see the structure of my application :
myWebsiteDirectory/
app/
__init__.py
setup.py
wsgi.py
And below you see the content of the python files:
setup.py
from setuptools import setup
setup(name='YourAppName',
version='1.0',
description='OpenShift App',
author='Your Name',
author_email='example@example.com',
url='http://www.python.org/sigs/distutils-sig/',
install_requires=['Flask>=0.10.1'],
)
wsgi.py
#!/usr/bin/python
import os
#virtenv = os.environ['OPENSHIFT_PYTHON_DIR'] + '/virtenv/'
virtenv = os.path.join(os.environ.get('OPENSHIFT_PYTHON_DIR','.'), 'virtenv')
virtualenv = os.path.join(virtenv, 'bin/activate_this.py')
try:
execfile(virtualenv, dict(__file__=virtualenv))
except IOError:
pass
#
# IMPORTANT: Put any additional includes below this line. If placed above this
# line, it's possible required libraries won't be in your searchable path
#
from app import app as application
#
# Below for testing only
#
if __name__ == '__main__':
from wsgiref.simple_server import make_server
httpd = make_server('localhost', 8051, application)
# Wait for a single request, serve it and quit.
httpd.serve_forever()
__init__.py
from flask import Flask
app = Flask(__name__)
app.debug = True
@app.route('/')
def not_again():
return 'Hello World!'
if __name__ == '__main__':
app.run(host='0.0.0.0', debug=True)
What is my question:
What happens when I upload this files on the server and what happens when a user request my website?
In the other words:
And again, in the other words:
Although the above question is based on Python & Flask web framework web developing, but it there is a general mechanism for all the languages and frameworks, please let me know that general procedure and not this specific case.
If you have no good idea about how a web server works, since you are interested in Python, I suggest you have a read of:
If interested then in a walk through of doing something with a Python web framework to build a site, then also consider reading:
It is a good basic introduction to get people going.
These will give you fundamentals to work with. How specific WSGI servers or service providers work can then be a bit different, but you will be better able to understand by working through the above first.