'Flask static send from localhost to server
I am deploying an application on localhost and listening on a port on a remote server which is bound to a domain, the application shows up fine on localhost and the static folder is not passed to the server, how can I solve this problem? My code:
nginx.conf:
server {
listen 3002;
server_name localhost;
location / {
include uwsgi_params;
uwsgi_pass web:5000;
}
}
docker-compose.yml:
version: "3.7"
services:
web:
build:
context: ./app
dockerfile: Dockerfile
restart: always
ports:
- "5000:5000"
nginx:
build:
context: ./nginx
dockerfile: Dockerfile
restart: always
ports:
- "3002:3002"
app.py:
from flask import Flask, render_template, request, redirect, url_for, send_from_directory
from flask_babel import Babel
# from flask.helpers import safe_join
import os
# from flask_babel import lazy_gettext as _l
from flask_sqlalchemy import SQLAlchemy
from flask_migrate import Migrate
from config import Config
from db_driver import DBDriver
db = SQLAlchemy()
migrate = Migrate()
# static = safe_join(os.path.dirname(__file__), 'static')
def create_app():
app = Flask(__name__)
# collect = Collect()
app.config.from_object(Config)
db.init_app(app)
migrate.init_app(app, db)
return app
app = create_app()
babel = Babel(app)
@babel.localeselector
def get_locale():
return request.accept_languages.best_match(app.config["LANGUAGES"])
# return 'uk'
@app.errorhandler(404)
def not_found_error(error):
return {"message": "Упс, помилочка 404!"}, 404
@app.route("/")
def index():
staff_list = DBDriver.get_staff_list()
return render_template("about.html", staff_list=staff_list)
if __name__ == "__main__":
app.run(debug=True, host="0.0.0.0")
Project structure:
|-app |-static |-templates | |-app.py
|-nginx |-nginx.conf
|
|-docker-compose.yml
|
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
