Django static只在开发时失败



部署的站点运行良好!然而,当我运行开发服务器时,它不会加载静态信息。访问时

localhost:9090/static 

它返回404页未找到并说:

Directory indexes are not allowed here.

请帮忙!

STATIC_ROOT = '/var/mysite/static/'
STATIC_URL = '/static/
DEBUG = True

已尝试:

-collectstatic method
-adding static_dir & urlpatterns += staticfiles_urlpatterns()

我是Django的新手,但我的设置(以及静态文件)中有以下内容:(我的项目的顶部目录中确实有一个名为static的文件夹)

# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.6/howto/static-files/
STATIC_URL = '/static/'
STATICFILES_DIRS = (
    os.path.join(BASE_DIR, "static"),
    '/path/to/static/',
)

在urls.py 中

from django.conf.urls.static import static
from django.contrib.staticfiles.urls import staticfiles_urlpatterns
from yourprojectname import settings
from django.views.generic.base import TemplateView
urlpatterns = patterns('',
    # url(r'^$', 'yourprojectname.views.home', name='home'),
    # url(r'^blog/$', blog),
)
urlpatterns += staticfiles_urlpatterns()

设置中.py

PROJECT_DIR = os.path.abspath(os.path.dirname(__file__))
STATIC_ROOT = os.path.join(PROJECT_DIR,'static')
STATIC_URL = '/static/'
STATICFILES_DIRS = (
    os.path.join(PROJECT_DIR,'static'), # if you name your static files folder is named as 'static'
)
TEMPLATE_DIRS = (
    os.path.join(PROJECT_DIR,'template'),
)

相关内容

  • 没有找到相关文章

最新更新