Py学习  »  问与答

[精华] django 1.8中写的网页无法加载css和JS

773743943 • 10 年前 • 6979 次点击  

STATIC_URL = '/static/'

STATICFILES_DIRS = 'c:/django/springshine/static'

还要设置什么东西呢?

Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/1117
文章 [ 5 ]  |  最新文章 10 年前
773743943
Reply   •   1 楼
773743943    10 年前

ok,谢谢大家,设置完成了。http://jingyan.baidu.com/article/db55b609a93b114ba30a2ffb.html参考的这个博客,一会就搞完了。打算再看看文档,加深一下了解。

773743943
Reply   •   2 楼
773743943    10 年前

@cundi-weibo urls.py要怎么设置呢。我把代码贴下面。模版index.html下的引用: <link href="/static/bootstrap.css" rel="stylesheet" type="text/css"> <link href="/static/mystyle.css" rel="stylesheet" type="text/css"> <script src="/static/jquery-2.1.4.min.js"></script> <script src="/static/bootstrap.min.js"></script> index.html是全局模版,不是app里面的模版,在根目录下的templates目录中存放。然后settings下设置: TEMPLATES = [ { 'BACKEND': 'django.template.backends.django.DjangoTemplates', 'DIRS': [os.path.join(BASE_DIR,'templates')], 'APP_DIRS': True,………………} ] 。STATIC_URL = '/static/'

STATICFILES_DIRS = 'c:/django/springshine/static' 。下面是全局urls.py下的设置: from contact import views

urlpatterns = [ url(r'^admin/', include(admin.site.urls)), url(r'^$',views.index), ]。 我需要在这个urls.py下增加什么配置呢?

773743943
Reply   •   3 楼
773743943    10 年前

@cundi-weibo urls.py要怎么设置呢。我把代码贴下面 模版index.html下的引用: <link href="/static/bootstrap.css" rel="stylesheet" type="text/css"> <link href="/static/mystyle.css" rel="stylesheet" type="text/css"> <script src="/static/jquery-2.1.4.min.js"></script> <script src="/static/bootstrap.min.js"></script> index.html是全局模版,不是app里面的模版,在根目录下的templates目录中存放。然后settings下设置: TEMPLATES = [ { 'BACKEND': 'django.template.backends.django.DjangoTemplates', 'DIRS': [os.path.join(BASE_DIR,'templates')], 'APP_DIRS': True,………………} ] STATIC_URL = '/static/'

STATICFILES_DIRS = 'c:/django/springshine/static' 下面是全局urls.py下的设置: from contact import views

urlpatterns = [ url(r'^admin/', include(admin.site.urls)), url(r'^$',views.index), ]。 我需要在这个urls.py下增加什么配置呢?

mugbya
Reply   •   4 楼
mugbya    10 年前

你在页面中怎么加载资源的呢? 你给的信息太少了....

cundi-weibo
Reply   •   5 楼
cundi-weibo    10 年前

@773743943

还有项目文件夹中的urls.py要配置