静态文件不是从单独的django staticfile应用程序提供的 [英] Static files not being served from seperate django staticfile application

查看:225
本文介绍了静态文件不是从单独的django staticfile应用程序提供的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用webfaction做一个简单的静态网站。我想我已经做了一切正常,但仍然我的静态文件(即css,图像)没有被提供。我使用本指南来设置:



http://docs.webfaction.com/software/django/getting-started.html



我做了他们告诉我的一切,简而言之:



1)制作单独的静态媒体应用程序



2)更新的settings.py



3)run

  python manage.py collectstatic 

以上所有内容都按计划进行了很多,现在我可以在我命名的staticfile应用程序中看到我的静态文件的 personalsitestatic 即可。我的django应用程序称为 personalsite



目录结构如下所示:




  • webapps

    • htdocs

    • personalsite

      • apache2

      • bin

      • lib

      • 个人网站

        • manage.py

        • 个人网站

          • settings.py,urls.py,ect


        • main

          • settings.py,urls.py,静态文件目录,ect




    • personalstiestatic

      • bootstrap

      • 自定义





我的settings.py中的相关值如下所示:

  STATIC_ROOT ='/ home /< myname> / webapps / personalsitestatic /'
STATIC_URL ='http://< sitename> .com / static /'
TEMPLATE_DIRS =(
/ home /< myname> / webapps / personalsite / PersonalWebsite / templates /,)

我没有任何额外的静态目录在main / static之外,所以我没有使用STATIC_DIRS。模板似乎加载正常,只是没有静态文件。当我用firefox的调试器/检查元素检查它只是说样式表无法加载。任何人都可以帮助我,或者至少给我一些调试建议?

解决方案

我很傻,没有挂载到/ static url,希望这有助于某人!


I'm using webfaction to make a simple static website. I think I have done everything correctly, but still my static files (i.e css, images) are not being served. I used this guide to set things up:

http://docs.webfaction.com/software/django/getting-started.html

I did everything they told me to, so in brief:

1) made a separate static media application

2) updated settings.py

3) ran

python manage.py collectstatic 

All of the above went pretty much according to plan and I can now see my static files in the staticfile application that I named personalsitestatic. My django application is called personalsite.

The directory structure looks like this:

  • webapps
    • htdocs
    • personalsite
      • apache2
      • bin
      • lib
      • PersonalWebsite
        • manage.py
        • PersonalWebsite
          • settings.py, urls.py, ect
        • main
          • settings.py, urls.py, static files directory, ect
    • personalstiestatic
      • bootstrap
      • custom

This is what the relevant values in my settings.py looks like:

STATIC_ROOT = '/home/<myname>/webapps/personalsitestatic/'
STATIC_URL = 'http://<sitename>.com/static/'
TEMPLATE_DIRS = (
"/home/<myname>/webapps/personalsite/PersonalWebsite/templates/",)

I don't have any additional static directories outside of main/static so I am not using STATIC_DIRS. The templates appear to be loading fine, just none of the static files. When I inspect with firefox's debugger/inspect element thing it just says "stylesheet could not be loaded". Can anyone help me out here or at least give me some suggestions for debugging?

解决方案

I was being silly and did not mount it to the /static url, hope this helps someone!

这篇关于静态文件不是从单独的django staticfile应用程序提供的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆