您的位置:首页 > Web前端 > JavaScript

Django记-模版与静态文件(js/css/image)

2014-08-29 13:00 465 查看
接上篇:

1.在helloapp文件夹中中建立模版文件夹templates

2.在helloapp/templates 文件夹中建立文件 index.html 文件

<!DOCTYPE html>
<html>
<body>

<h1>模版文件</h1>

<p>我的第一模版文件。</p>

</body>
</html>


3.改写views.index() 方法.

from django.shortcuts import render
from django.http import HttpResponse
from django.template import loader, Context

def index(request):
pass
temp = loader.get_template('index.html')
con = Context({})
return HttpResponse(temp.render(con))


3.运行 manage.py runserver .
4. 就可以访问 http://127.0.0.1:8000/index
更方便的方法:

views.index()方法也可以这么写

from django.shortcuts import render_to_response

def index(request):
pass
return render_to_response('index.html',{})


关于静态文件:

要在django 中引用静态文件,在路径中建立 helloapp/static/文件夹,所有的静态文件都存放到这里. 

├─helloapp

│  ├─static

│  │  ├─css

│  │  ├─image

│  │  ├─js

│  │  ├─rsc

│  │  │  └─img

│  │  │      ├─askanswer

│  │  │      ├─ava

│  │  │      ├─browsersave

│  │  │      ├─cmthot

│  │  │      ├─guide

│  │  │      ├─loginopen

│  │  │      ├─radar

│  │  │      └─recommendTa

│  │  ├─smui

│  │  │  ├─css

│  │  │  ├─fonts

│  │  │  ├─images

│  │  │  └─javascript

│  │  └─um

│  │      ├─lang

│  │      │  ├─en

│  │      │  │  └─images

│  │      │  └─zh-cn

│  │      │      └─images

│  │      ├─themes

│  │      │  └─default

│  │      │      ├─images

│  │      │      └─_css

│  │      ├─third-party

│  │      └─umeditorsrc

│  │          ├─adapter

│  │          ├─core

│  │          ├─plugins

│  │          └─ui

│  └─templates

Django 1.6 的setting 文件 基本不用配置
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  django 教程