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

    1 answer 1

    The question was resolved. What are the pitfalls, I decided to write the same as I, beginners, I think the pros do not need. The Apache misite.local.conf file in <Directory /var/www/misite.local/cgi-bin> AllowOverride None ,

    This is just a permission for processing .htaccess. ScriptAlias /cgi-bin /var/www/misite.local/cgi-bin/ fixed on ScriptAlias /cgi-bin/ /var/www/misite.local/cgi-bin/ (slash added)

    Regarding .htaccess, if not strange taken from here http://flask.pocoo.org/docs/0.10/deploying/cgi/

     RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f # Don't interfere with static files RewriteRule ^(.*)$ /path/to/the/application.cgi/$1 [L] 

    only earned after deleting the comment # and all that is behind it.
    Naturally /path/to/the/application.cgi/ replaced by /cgi-bin/test.cgi and added RewriteBase /

    (Modfor mod_rewrite excellent publications _https: //www.opennet.ru/base/dev/mod_rewrite_guide.txt.html, _https: //www.opennet.ru/docs/RUS/mod_rewrite/ and _https: //habrahabr.ru / company / sprinthost / blog / 129560 /)

    File (script) views.py

     from yourapplication import app from flask import render_template @app.route('/') def index(): user = {'nickname':'Test1'} return render_template('index.html', title='Home', user=user) @app.route('/home') def index1(): user = {'nickname':'Test2'} return render_template('index.html', title='Home', user=user) @app.route('/tst') def index2(): user = {'nickname':'Test3'} return render_template('index.html', title='Home', user=user) 

    Please note that the name of the functions is different (just in case) and if you have, for example, the / home directory in the site root (/) then apache will get into it and the function in the script will not be processed, indisputably with mod_rewrite or something like that You can fight, but I did not set out to deal with this. In general, the hosting test is passed, you can go into the study of Flask