Flask send_from_directory()用于生产目的

时间:2015-09-15 03:06:20

标签: python apache flask

在我的Rails.application.routes.draw do root 'welcome#welcome' get 'login' => 'sessions#login', :as => :login get 'dashboard' => 'users#dashboard', :as => :dashboard post 'logging/user' => 'sessions#create' get 'logout' => 'sessions#destroy', :as => :logout get 'about' => 'about' get 'newsfeed' => 'users#newsfeed' resources :users, except: :show get 'profile/:user_id' => 'users#show', as: :profile resources :posts do resources :comments end get 'index' => 'posts#index' get 'register' => 'users#new', :as => :register end 文件中,我有

app.py

我已经在很多SO帖子中读过,使用Flask来提供静态文件对于生产来说是一个坏主意。如果我计划使用Apache服务器进行生产,我该怎么办?

1 个答案:

答案 0 :(得分:0)

基本上,您需要一些重写规则,以便Apache可以找到这些文件,如下所示:

Alias /static/ /var/www/hello-world/static

并在需要时重定向到apache:

id = request.args.get('id')
# if id is in database (if request is valid):
    return redirect('/files/file.ext') # use the correct url written in rewrite rules
else:
    abort(403)