Skip to content

Instantly share code, notes, and snippets.

View jrm2k6's full-sized avatar

Jeremy Dagorn jrm2k6

View GitHub Profile
@jrm2k6
jrm2k6 / deploiement.md
Last active December 31, 2017 13:36
Déploiement d'une application flask sur alwaysdata (english version on http://flask-blog.jeremydagorn.com)

Contexte

J'utilise les services offerts par Alwaysdata depuis plus de deux ans maintenant. J'y ai deployé des applis Rails, Django. Cette fois, j'ai voulu m'essayer à du Python une nouvelle fois, mais par l'intermédiaire de Flask. Ce ne fut pas si facile que cela. Pour votre informationm je suis totalement débutant en tout ce qui concerne déploiement et administration système (malgré le fait d'être un utilisateur Linux quotidien). Je fus découragé rapidement devant le manque de documentation concernant le déploiement d'une appli flask sur alwaysdata. C'est pourquoi j'ai décidé d'écrire cet article qui va vous tenter de vous guider pas à pas.

  • installation de python (2.7.5)
  • installation de setuptools et pip
  • installation de virtualenv
  • installation de flask et des librairies requises par votre application.
  • créaction de votre fichier .wsgi
(env7)jeremydagorn@ssh:~/www/jeremydagorn-blog$ python
Python 2.7.5 (default, Feb 10 2014, 21:16:24)
[GCC 4.3.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from lxml import etree
>>>
jeremydagorn@ssh:~/admin/log$ tail -f error.log
@jrm2k6
jrm2k6 / gist:8905880
Created February 9, 2014 21:01
Override model views for Flask Admin to not display blank dropdown for models with relationship annotation
#models.py
import sqlalchemy
from flask_sqlalchemy import SQLAlchemy
from sqlalchemy.orm import class_mapper, ColumnProperty
db = SQLAlchemy()
class User(db.Model):
[Thu Feb 06 19:39:58 2014] [error] [client 72.220.215.219] rv = self.handle_user_exception(e)
[Thu Feb 06 19:39:58 2014] [error] [client 72.220.215.219] File "/home/jeremydagorn/.virtualenvs/env7/lib/python2.7/site-packages/flask/app.py", line 1381, in handle_user_exception
[Thu Feb 06 19:39:58 2014] [error] [client 72.220.215.219] reraise(exc_type, exc_value, tb)
[Thu Feb 06 19:39:58 2014] [error] [client 72.220.215.219] File "/home/jeremydagorn/.virtualenvs/env7/lib/python2.7/site-packages/flask/app.py", line 1475, in full_dispatch_request
[Thu Feb 06 19:39:58 2014] [error] [client 72.220.215.219] rv = self.dispatch_request()
[Thu Feb 06 19:39:58 2014] [error] [client 72.220.215.219] File "/home/jeremydagorn/.virtualenvs/env7/lib/python2.7/site-packages/flask/app.py", line 1461, in dispatch_request
[Thu Feb 06 19:39:58 2014] [error] [client 72.220.215.219] return self.view_functions[rule.endpoint](**req.view_args)
[Thu Feb 06 19:39:58 2014] [error] [client 72.220.215.219] File "/home
->tree -L 2
.
├── Procfile
├── README.md
├── app.wsgi.example
├── authentication.py
├── base.py
├── tests
│   ├── __init__.py
│   ├── test_base_bis.py
-- problem 48
tablen f n = do
let r = generateResultsAsStrings f n
mapM_ putStrLn r
generateResultsAsStrings :: ([Bool] -> Bool) -> Int -> [String]
generateResultsAsStrings f n = map unwords $ map (\x -> (map show x ++ [show (f x)])) $ sequence $ replicate n [True, False]
infixl 4 `and'`
and' :: Bool -> Bool -> Bool
and' False _ = False
and' _ False = False
and' _ _ = True
infixl 4 `or'`
or' :: Bool -> Bool -> Bool
or' True _ = True
or' _ True = True
import Data.List (nub, group)
-- problem 31
isPrime :: Int -> Bool
isPrime n = length (filter (\x -> (mod n x) == 0) [2..n-1]) == 0 && n > 1
-- problem 32
pgcd :: Int -> Int -> Int
pgcd a 0 = a
pgcd a b = pgcd b (mod a b)
import Data.List (nub, group)
-- problem 31
isPrime :: Int -> Bool
isPrime n = length (filter (\x -> (mod n x) == 0) [2..n-1]) == 0 && n > 1
-- problem 32
pgcd :: Int -> Int -> Int
pgcd a 0 = a
pgcd a b = pgcd b (mod a b)
-- problem 28
compareLength::(Int, [a]) ->(Int, [a]) -> Ordering
compareLength a1 a2 = if (fst a1 > fst a2) then GT else LT
lsort :: [[a]] -> [[a]]
lsort l = map (\x -> (snd x) ) $ sortBy compareLength $ map (\x -> (length x, x)) l