django 关于html、css、js 目录位置

项目目录:

project/

---------------init.py

---------------views.py

---------------settings.py

---------------urls.py

---------------static/

-----------------------css/

----------------------------css.css

-----------------------js/

---------------------------js.js

-----------------------img/

---------------root/

---------------------templates/

--------------------------------index.html

settings.py :

1.INSTALLED_APPS加入三个APP(root、search、detail)

2.加入static(存放静态网页的css、js、img)的文件夹

STATIC_URL = '/static/'

STATIC_ROOT = os.path.join(os.path.dirname(file),'static')

STATICFILES_DIRS = (

('css',os.path.join(STATIC_ROOT,'css').replace('\','/')),

('js',os.path.join(STATIC_ROOT,'js').replace('\','/')),

('img',os.path.join(STATIC_ROOT,'img').replace('\','/')),

)

3.html引用添加上目录:

urls.py :

添加url的指向目录(各个views)注意:先定义后使用

from django.conf.urls import url

from root import views as root_views #定义

from search import views as search_views

from detail import views as detail_views

urlpatterns = [
url(r'^$', root_views.index), #使用 # 默认
url(r'^search/',search_views.index),
url(r'^detail/',detail_views.index),
]

各个APP新建templates,将各个html放置进去

views.py :

from django.shortcuts import render

def index(request):
return render(request,'index.html')
上一篇:Java程序员从笨鸟到菜鸟全部博客目录


下一篇:[Mac A]为什么国外程序员爱用 Mac?