python - 找不到 apache2 flask 应用程序 css 文件?

标签 python html css flask apache2

我一直在尝试在 apache2 上部署 Flask 应用程序,但在提供 css 文件时遇到问题。在浏览器中打开我的应用程序后,我收到控制台中找不到文件的 404 错误。

文件夹结构如下:

/var/www/website/catalog.wsgi
/var/www/website/app/static/styles.css

apache 的 .conf 文件配置如下:

<VirtualHost *:80>
    ServerName 18.130.209.7
    ServerAlias http://ec2-18-130-209-7.eu-west-2.compute.amazonaws.com
    ServerAdmin admin@18.130.209.7
    WSGIDaemonProcess catalog python-path=/var/www/website:/var/www/website/venv/lib/python2.7/site-packages
    WSGIProcessGroup catalog
    WSGIScriptAlias / /var/www/website/catalog.wsgi
    <Directory /var/www/website/app/>
        Order allow,deny
        Allow from all
    </Directory>
    Alias /static /var/www/webstie/app/static
    <Directory /var/www/website/app/static/>
        Order allow,deny
        Allow from all
    </Directory>
    <Directory /var/www/website/app/api>
        Order allow,deny
        Allow from all
    </Directory>
    <Directory /var/www/website/app/auth>
        Order allow,deny
        Allow from all
    </Directory>
    <Directory /var/www/website/app/site>
        Order allow,deny
        Allow from all
        </Directory>
    <Directory /var/www/website/app/templates>
        Order allow,deny
        Allow from all
    </Directory>
    AliasMatch "(?i)^/([^/]+)/static/(.*)$" "/var/www///static/$2"
    <Directory "var/www/website/app/[^/]+/static/.*">
      Order allow,deny
      Allow from all
    </Directory>
    ErrorLog ${APACHE_LOG_DIR}/error.log
    LogLevel warn
    CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

index.html 文件中的导入语句如下所示:

<link rel="stylesheet" type="text/css" href="{{ url_for('static', filename='styles.css') }}" />

/app文件夹下的init.py文件中包含如下语句:

app.static_folder = 'static'

知道为什么浏览器找不到 CSS 文件吗??? 感谢所有的帮助。

最佳答案

在 .conf 文件中有一个我之前没有注意到的拼写错误:

Alias /static /var/www/webstie/app/static

将其固定为“网站”,现在一切正常。

关于python - 找不到 apache2 flask 应用程序 css 文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54782861/

相关文章:

css - Bootstrap 容器类部分响应

javascript - jquery文本中使用鼠标只选中一个单词

python - 将类型为 'object' 的数据帧列转换为类型列表

html - 如何使用 CSS&HTML 来创建像这样的 Volume Ctrl bar 样式?

html - 在某些机器上,Safari 中的边距更多

css - 使用 bootstrap css 固定页脚

Python - 元素树查找

python - Django 根据 url 请求预填写表单下拉框

python - 是否可以将 "Domain-wide Delegation of Authority"与 gdata-python-client 一起使用?

javascript - 无法重定向另一个页面中的输出(HTML、Javascript)