Farid Ahmadian / Python

Python Flask FrameWork


downloadchibashi.py


import logging
from logging.handlers import RotatingFileHandler

from flask import Flask
from flask import send_from_directory
import urllib
import urllib2
#from BeautifulSoup import BeautifulSoup
import re

app = Flask(__name__, static_folder='static')

@app.route('/')
def root():
    return ':D :) Hello World!' 


@app.route('/uploads/<path:filename>')
def download_file(filename):
    #return send_from_directory(app.config['UPLOAD_FOLDER'],filename, as_attachment=True)
    print app.static_folder
    return send_from_directory(app.static_folder,filename, as_attachment=True)

if __name__ == '__main__':
    handler = RotatingFileHandler('foo.log', maxBytes=10000, backupCount=1)
    handler.setLevel(logging.INFO)
    app.logger.addHandler(handler)
    app.run(debug=True)

downloadchibashi.wsgi


from downloadchibashi import app as application
import sys
sys.stdout = sys.stderr

downloadchibashi.conf


<VirtualHost *:80>
    ServerName downloadchibashi.com 
    ServerAlias www.downloadchibashi.com
    ServerAdmin webmaster@localhost

    WSGIDaemonProcess downloadchibashi user=farid gro up=farid threads=5 python-path=/home/farid/htdocs/downloadchibashi/

    WSGIScriptAlias / /home/farid/htdocs/downloadchibashi/downloadchibashi.wsgi
    DocumentRoot /home/farid/htdocs/downloadchibashi/static
    <Directory /home/farid/htdocs/downloadchibashi/>
           WSGIProcessGroup downloadchibashi
           WSGIApplicationGroup %{GLOBAL}
           Order deny,allow
       Require all granted
    </Directory>

    ErrorLog ${APACHE_LOG_DIR}/downloadchibashi_error.log
    CustomLog ${APACHE_LOG_DIR}/downloadchibashi_access.log combined
</VirtualHost>

BY: Farid Ahmadian
TAG: python, flask, apache
DATE: 2015-01-27 19:36:53


Farid Ahmadian / Python [ TXT ]

With many thanks and best wishes for dear Pejman Moghadam, someone who taught me alot in linux and life :)