Django + Apache2 上的静态文件给出 URLconf 错误
Static files on Django + Apache2 gives URLconf error
我正在尝试将下载的 bootstrap 主题整合到我的实时网站中
我在 django 项目的根目录(manage.py 所在的位置)有一个 /static 目录,其中包含我所有的 css/javascript 文件。
来自我的settings.py
STATIC_URL = '/static/'
STATICFILES_DIR = '/var/www/html/aerocredRoot/static'
在我的index.html
{% load static %}
...href="{% static 'assets/web/.......' %}">
和我的urls.py
urlpatterns = [
url(r'^%', views.index),
url(r'^admin/', include(admin.site.urls)),
]
使用 Django 1.11.13。
在带有互联网浏览器的网络检查器上,我不断收到
Using the URLconf defined in Aerocred.urls, Django tried these URL
patterns,in this order:
^$
^admin/
The current URL, static/assets/bootstrap/css/bootstrap.min.css, didn't match any
of these.
我试过将静态文件夹移动到我的应用程序的子目录,弄乱了 STATIC_ROOT 并做了 collectstatic 的东西无济于事。
我觉得应该是{% load staticfiles %}
.
请确保要加载的格式是 {% load static %} 而不是 (% load static %)。
你 运行 python manage.py collectstatic
将静态文件存储在 /var/www/html/aerocredRoot/static 中了吗?
所以我想通了,
我需要按照 Django 文档中的说明遵循此约定。所以我编辑了我的 urls.py 以匹配这个...
from django.conf import settings
from django.conf.urls.static import static
urlpatterns = [
# ... the rest of your URLconf goes here ...
] + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
然后编辑 settings.py 定义
PROJECT_DIR = os.path.dirname(os.path.abspath(__file__))
STATIC_ROOT = os.path.join(PROJECT_DIR, 'static')
STATIC_URL = '/static/'
STATICFILES_DIR = '/var/www/html/aerocredRoot/static'
我正在尝试将下载的 bootstrap 主题整合到我的实时网站中
我在 django 项目的根目录(manage.py 所在的位置)有一个 /static 目录,其中包含我所有的 css/javascript 文件。
来自我的settings.py
STATIC_URL = '/static/'
STATICFILES_DIR = '/var/www/html/aerocredRoot/static'
在我的index.html
{% load static %}
...href="{% static 'assets/web/.......' %}">
和我的urls.py
urlpatterns = [
url(r'^%', views.index),
url(r'^admin/', include(admin.site.urls)),
]
使用 Django 1.11.13。
在带有互联网浏览器的网络检查器上,我不断收到
Using the URLconf defined in Aerocred.urls, Django tried these URL
patterns,in this order:
^$
^admin/
The current URL, static/assets/bootstrap/css/bootstrap.min.css, didn't match any
of these.
我试过将静态文件夹移动到我的应用程序的子目录,弄乱了 STATIC_ROOT 并做了 collectstatic 的东西无济于事。
我觉得应该是{% load staticfiles %}
.
请确保要加载的格式是 {% load static %} 而不是 (% load static %)。
你 运行 python manage.py collectstatic
将静态文件存储在 /var/www/html/aerocredRoot/static 中了吗?
所以我想通了,
我需要按照 Django 文档中的说明遵循此约定。所以我编辑了我的 urls.py 以匹配这个...
from django.conf import settings
from django.conf.urls.static import static
urlpatterns = [
# ... the rest of your URLconf goes here ...
] + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
然后编辑 settings.py 定义
PROJECT_DIR = os.path.dirname(os.path.abspath(__file__))
STATIC_ROOT = os.path.join(PROJECT_DIR, 'static')
STATIC_URL = '/static/'
STATICFILES_DIR = '/var/www/html/aerocredRoot/static'