Jump to content

[Answered] How Do I Use Flask On Johnny


study

Recommended Posts

Hi... please help me...

I'm just have one of problem.

I want to use python but i don't know to setting to flask.

i did searching google,

 

file: public-html/cgi-bin/cgi.cgi

 

#!/usr/bin/python
from wsgiref.handlers import CGIHandler
from views import app
import os
import cgitb; cgitb.enable()
os.environ['SERVER_NAME'] = '127.0.0.1'
os.environ['SERVER_PORT'] = '5000'
os.environ['REQUEST_METHOD'] = 'GET'
os.environ['PATH_INFO'] = ""
CGIHandler().run(app)

 

file: views.py

 

from flask import Flask
app = Flask(__name__)
@app.route("/")
def hello():
return "This is Hello World!\n"
if __name__ == "__main__":
app.run()

 

file: .htaccess

 

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ /home/USERNAME/public_html/cgi-bin/cgi.cgi/$1 [L]

 

...

i had connect to host on web

it's just show me that text '/Index'

 

also i was uploaded files that i made to python files and html files in templates folder but it is not working.

 

My english is so bad...sorry. please help me ㅠㅠㅠㅠ

Link to comment
Share on other sites

  • 3 weeks later...

From what I understand flask is used primarily on home computers where you might not have access to a mature tested apache server to test your python web scripts in a fully python environment. As soon as someone explains why they need flask to do something that django/apache cgi can't already do I'll be listening. Apache configuration can be daunting and complex. I get it. I'm the one that configures it, but the main advantage to flask is being able to run a janky webserver super easily by simply running the command ./runserver, but you really don't need that if you have a real http/https server.

Link to comment
Share on other sites

  • 1 month later...

Hi, thanks for a great hosting site, I'd also would like to be able to play with Flask, the reason being that it's easier to use as a simple Rest Api framework, I don't need/want a full ORM, nor database models, nor migration, nor user authentication, just a plain old simple rest api.

Link to comment
Share on other sites

Alright!

 

Create a folder in public_html called flask

/home/username/public_html/flask/
In that folder create a .htaccess file: /home/username/public_html/flask/.htaccess

RewriteEngine On
RewriteBase /
RewriteRule ^(media/.*)$ - [L]
RewriteRule ^(admin_media/.*)$ - [L]
RewriteRule ^(flask\.wsgi/.*)$ - [L]
RewriteRule ^(.*)$ flask/flask.wsgi/$1 [QSA,PT,L]
Create a file named flask.wsgi

import os, sys

# edit your username below
sys.path.append("/home/username/public_html/flask");

sys.path.insert(0, os.path.dirname(__file__))
from myapp import app as application

# make the secret code a little better
application.secret_key = 'secret'
Create a python script named myapp.py

import sys

from flask import Flask, __version__
app = Flask(__name__)
application = app

@app.route("/")
def hello():
  return """

    HelioHost rules!<br><br>
    <a href="/flask/python/version/">Python version</a><br>
    <a href="/flask/flask/version/">Flask version</a>

  """

@app.route("/python/version/")
def p_version():
  return "Python version %s" % sys.version

@app.route("/flask/version/")
def f_version():
  return "Flask version %s" % __version__

if __name__ == "__main__":
  app.run()
Here is the working example: https://krydos.heliohost.org/flask/

 

This will only work on Tommy at the moment. Feel free to play around with it and let me know if you have any issues. If everything is working I'll see about writing up a wiki and making a news post about HelioHost now supporting flask.

Edited by Krydos
Specified location of .htaccess
  • Like 1
Link to comment
Share on other sites

  • 2 months later...

Hi Krydos,

I'm just a new user and I'm also interested in using Flask. I activated my account last night and was dropped to Johnny. If I remember right, Tommy was marked as full. So my question is, if there is any chance to use Flask on Johnny in the nearer future ?

 

Thanks for your advice

 

Jürgen

Link to comment
Share on other sites

Flask is only available on Tommy. Ruby on Rails and Flask/Django don't play well together so we have to choose one or the other basically. We choose RoR on Johnny and Flask/Django on Tommy. If you need RoR you have to pick Johnny, and if you need Flask you have to pick Tommy. Python 3.6 and cgi are available on both servers. Once we get Ricky online in the next month or so we will have Flask/Django on that server as well.

 

http://wiki.helionet.org/Moving_your_account

Link to comment
Share on other sites

  • 3 months later...
  • 7 months later...
  • 1 year later...

Sorry to revive a dead thread but I've copied those files line for line (replacing `username` with my username) and I get a 404 at https://yalefwd.heliohost.org/flask/. Not really sure how to troubleshoot.

[Fri Mar 13 21:45:28.922007 2020] [wsgi:error] [pid 14249] [client 38.126.101.151:36244] Target WSGI script not found or unable to stat: /home/yalefwd/public_html/flask/flask.wsgi

 

Edited by scottgigante
Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
×
×
  • Create New...