Django基础

Django相关

Django Templates相关

static文件夹配置及引用

1
2
3
4
#setting.py中设置
STATICFILES_DIRS = (
os.path.join(BASE_DIR, 'static'),
)
1
2
#templates html中引用
<script src="{% static "js/jquery.min.js" %}"></script>

####动态URL

1
2
3
4
5
6
7
8
9
10
11
#urls.py中配置
urlpatterns = [
url(r'^$', index, name='index'),
]
#views.py中配置
def index(req):

# return HttpResponse("aa")
<del>return render_to_response('index.html',)</del>
#render_to_response貌似已经不推荐使用,会在后期版本内删除
return render(req,'index.html')

1
2
#templates文件中引用
<h1><a href="{% url "index" %}">WILD LIFE</a></h1>