8
8
891099838382014-12-16 06:44:18
Flask
89109983838, 2014-12-16 06:44:18

Flask-admin changes url on redirects how to fix?

Good time of the day.
The problem is that when you go to the administrative part (and just on redirects in a non-administrative part), the path is changed. so to speak!
I can’t find words to explain, I’ll better demonstrate:
the hoster has a server, flask is raised on it, the settings are as follows:
.htaccess

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ cgi-bin/flask-wrapper.fcgi/$1 [QSA,L]

flask-wrapper.fcgi
#!/home/profel/python/bin/python
# -*- coding: utf-8 -*-
import sys, os
reload(sys)
sys.setdefaultencoding('utf8')

# Add a custom Python path.
sys.path.insert(0, "/home/profel/site/")

# Switch to the directory of your project. (Optional.)
os.chdir("/home/profel/site/")

from flup.server.fcgi import WSGIServer
from app import app

if __name__ == '__main__':
    WSGIServer(app).run()

Everything works great, but for example, if you enter the path
http_://site.ru/admin/
then after the page starts loading, the path changes to
http_://site.ru/cgi-bin/flask-wrapper.fcgi/admin/
However, this concerns and not only Flask-Admin also opens any redirect on the client side of the site.
http_://site.ru/cgi-bin/flask-wrapper.fcgi/redirect_page/
It seems that there are no technical problems with this - it's just not nice and "uncomfortable"!
I will add that on a home PC an exact copy of the site works without these glitches (Windows + built-in Flask test server).

Answer the question

In order to leave comments, you need to log in

1 answer(s)
8
89109983838, 2014-12-17
@89109983838

I found the answer myself!
And it lies in the fact that it is necessary to read the mana more carefully !!! :(
. I don't have access to Apache settings, so the option is:

<IfModule mod_fcgid.c>
   AddHandler fcgid-script .fcgi
   <Files ~ (\.fcgi)>
       SetHandler fcgid-script
       Options +FollowSymLinks +ExecCGI
   </Files>
</IfModule>

<IfModule mod_rewrite.c>
   Options +FollowSymlinks
   RewriteEngine On
   RewriteBase /
   RewriteCond %{REQUEST_FILENAME} !-f
   RewriteRule ^(.*)$ cgi-bin/flask-wrapper.fcgi/$1 [QSA,L]
</IfModule>

#!/home/profel/python/bin/python
# -*- coding: utf-8 -*-
import sys, os
reload(sys)
sys.setdefaultencoding('utf8')

sys.path.insert(0, ' /home/profel/site/')

from flup.server.fcgi import WSGIServer
from app import app

class ScriptNameStripper(object):
   def __init__(self, app):
       self.app = app

   def __call__(self, environ, start_response):
       environ['SCRIPT_NAME'] = ''
       return self.app(environ, start_response)

app = ScriptNameStripper(app)

if __name__ == '__main__':
    WSGIServer(app).run()

By the way, I'll point to this piece of code
import sys, os
reload(sys)
sys.setdefaultencoding('utf8')

Using it, I solved the problem with the output of Russian letters from *.py files (on hosting and test server .. windows).
(apparently, the hoster's console, like cmd, is not in UFT8. To fix the ailment when the application starts, we overload the console with the default encoding set to UTF8. something like this ....)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question