css应用

检查配置文件alu02/settings.py

# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.9/howto/static-files/

STATIC_URL = '/static/'

 

 

创建alu02/blog/templates/register.html

<?xml version="1.0" encoding="UTF-8"?> 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    {% load staticfiles %}
    <link rel="stylesheet" type="text/css" href="{% static "css/mystyle.css" %}"/>
</head>

<body>
<form method="POST">
{{form}}
<input type='submit' value='register'/>
</form>
</body>
</html>

 

新建css

[root@host-100-100-5-17 alu02]# cat blog/static/css/mystyle.css 
body {
    background-color: yellow;
}
[root@host-100-100-5-17 alu02]# 

 

启动server

[root@host-100-100-5-17 alu02]# python manage.py runserver

 

测试界面

 

注意:虽然form表单是由django生成,但是在显示时也会受css控制,所以django不需要在程序中自己定义css。

 

posted on 2016-03-09 15:43  onmyway227  阅读(179)  评论(0编辑  收藏  举报

导航