Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 02/09/2024 in all areas

  1. We will update our wiki article on how to get started with Flask eventually, but just posting a quick example here so people can comment and ask questions on this thread. Create a directory on your main domain called flasktest. If you were transferred from cPanel your main domain will be parked on the public_html directory. If you created a new account on Plesk your directory will be httpdocs. Create an .htaccess file inside the flasktest directory with these contents: Options +ExecCGI RewriteEngine On RewriteBase / RewriteRule ^(media/.*)$ - [L] RewriteRule ^(admin_media/.*)$ - [L] RewriteRule ^(flask\.wsgi/.*)$ - [L] RewriteRule ^(.*)$ flasktest/flask.wsgi/$1 [QSA,PT,L] Create a file named flask.wsgi inside the flasktest directory with these contents: import os, sys # edit your path below sys.path.append("/home/domain.helioho.st/httpdocs/flasktest"); sys.path.insert(0, os.path.dirname(__file__)) from myapp import app as application # set this to something harder to guess application.secret_key = 'secret' Create a file named myapp.py inside the flasktest directory with these contents: import sys from flask import Flask, __version__ app = Flask(__name__) application = app @app.route("/") def hello(): return """ Flask is working on HelioHost.<br><br> <a href="/flasktest/python/version/">Python version</a><br> <a href="/flasktest/flask/version/">Flask version</a> """ @app.route("/python/version/") def p_version(): return "Python version %s<br><br><a href='/flasktest/'>back</a>" % sys.version @app.route("/flask/version/") def f_version(): return "Flask version %s<br><br><a href='/flasktest/'>back</a>" % __version__ if __name__ == "__main__": app.run() Make sure your directory structure and files look like this: flasktest/ ├── flask.wsgi ├── .htaccess └── myapp.py 0 directories, 3 files If you did everything right it should look like this: https://krydos.heliohost.org/flasktest/ *** Please note that since wsgi uses server side caching your changes might not appear immediately, and in some cases might take several hours to update. We recommend developing your Flask app on your home computer and hosting the production copy on the server.
    1 point
  2. For anyone interested, here's a zip file with Krydos' Flask example: https://kairion.helioho.st/flasktest.zip Just download it and extract on httpdocs (Plesk's new account) or public_html (cPanel's transferred account), open flask.wsgi (which is inside the directory flasktest that'll be created when extracting the downloaded zip file) and find: sys.path.append("/home/YOUR_DOMAIN_HERE/httpdocs/flasktest"); And change YOUR_DOMAIN_HERE with your actual domain, e.g.: sys.path.append("/home/kairion.helioho.st/httpdocs/flasktest"); And then you can access your Flask example: https://kairion.helioho.st/flasktest/ @krsmith28p Here's a zip file with Krydos' Flask example adapted to run on web root (httpdocs for Plesk's new account or public_html for cPanel's transferred account): https://kairion.helioho.st/flasktest_on_webroot.zip Just extract it on your web root (as indicated above), remove all index files that it may have (index.html, index.htm, index.php etc.), open the file flask.wsgi and find: sys.path.append("/home/YOUR_DOMAIN_HERE/httpdocs"); And change YOUR_DOMAIN_HERE with your actual domain, e.g.: sys.path.append("/home/kairion.helioho.st/httpdocs"); It will work the same way as Krydos' original example. You can read these three files and check the differences between them and Krydos' originals. It's actually really easy: I just found all references for "flasktest" (the directory we make in the original example) and removed them (or changed them to a simple "/"). I'm not a Python/Django/Flask expert, but feel free to ask any questions and if I can help, I'll be glad to.
    1 point
  3. I missed the fact that the URL has to have the '/flasktest/' on the end (as in http://myname.helioho.st/flasktest/) Without that, it shows the index.html file (in my case the original 'hosting' site version). Spent 24 hours thinking it wasn't working....
    1 point
×
×
  • Create New...