I will begin in order with the description of OS Linux Ubuntu 14 ....
Apache2 server
Python 2.7
Directory structure:
Misite.local / / cgi-bin/ /yourapplication /templates /index.html /views.py /__init__.py /test.cgi /.htaccess .htaccess contains DirectoryIndex /cgi-bin/testcg.cgi and Options -Indexes
Apache file misite.local.conf
ScriptAlias /cgi-bin /var/www/misite.local /cgi-bin/testcg.cgi <Directory /var/www/misite.local/cgi-bin> AllowOverride All Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch Order allow,deny Allow from all </Directory> <Directory /var/www/misite.local > AllowOverride All </Directory> Test.cgi file
#!/var/www/home/menv/bin/python from wsgiref.handlers import CGIHandler from yourapplication import app CGIHandler().run(app) Init .py file
from flask import Flask app = Flask(__name__) import yourapplication.views views.py file
from yourapplication import app from flask import render_template @app.route('/') @app.route('/cgi-bin') def index(): user = {'nickname': 'Testttt'} # fake user return render_template('index.html', title='Home', user=user) File /templates/index.html
<html> <head> {% if title %} <title>{{ title }} - microblog</title> {% else %} <title>Welcome to microblog</title> {% endif %} </head> <body> <h1>Hi, {{ user.nickname }}!</h1> {% for post in posts %} <div><p>{{ post.author.nickname }} says: <b>{{ post.body }}</b></p></div> {% endfor %} </body> </html> Translation code on Habré ( https://habrahabr.ru/post/193242/ ) or ( http://blog.miguelgrinberg.com/post/the-flask-mega-tutorial-part-i-hello-world )
When accessed _http: //misite.local/cgi-bin works. Despite the decorator @ app.route ('/') when accessing _http: //misite.local, returns
The requested URL was not found on the server. If you entered the URL manually please check your spelling and try again.
If you put in the file Apache misite.local.conf
ScriptAlias /cgi-bin /var/www/misite.local/cgi-bin/ Returns
The requested URL was blah blah
Why from wsgiref.handlers import CGIHandler , only cgi works on hosting, everything needs to be processed, like _ http: //misite.local/, etc.
I can’t imagine what to do. I’ve already lost two days of Google wandering in the infe. While it is not clear where to dig, in the direction of apacha or flask (a). (Well, that worked at all).
How to make this whole thing right? And yet, on the hosting I do not have access to Apache configs, only to .htaccess