写在前面,为了学django,之前看了几周的前端知识,虽然不是很扎实,但基本的读写能力还是有的。之前加载css样式,都是采用本地直接加载,用链接的方式,这个应该不会有人用这个吧。。。这次写视图同样使用的本地加载的模式,使用报错,一开始还找了一个前端帮我看,他也说奇了怪了,为啥加载不到,让我给他发过去,他本地看。打包发过去,他直接打开。。。OK的。现在知道原因是直接打开页面是没问题的,当然我是一脸懵逼呀,咋回事,灵异事件?坚信一句,没有啥问题是重启解决不了的,于是重启电脑。。。打开页面OK,激动了五秒钟。运行,url打开。。。还一样没有样式。。。我彻底绝望了,咋回事呢。昨晚正好失眠了,想想,要不百度一下。。。终于解决了。真是心路历程呀。
一句话总结:django框架在使用css样式加载的时候,需要使用静态文件加载。
1.在配置文件setting.py中配置全局变量
STATIC_URL = '/static/'
STATICFILES_DIRS = (
os.path.join(BASE_DIR, 'static/'),
)
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'login',
]
这是配置的目录,你把样式放在哪个目录下,变量就是啥
2.视图
{% load staticfiles %}
<!doctype html>
<html lang="en">
<head>
<!-- Required meta tags -->
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
{# <meta http-equiv='Content-type' content='text/htm'>#}
<!-- 上述meta标签*必须*放在最前面,任何其他内容都*必须*跟随其后! -->
<link href="{% static 'css/bootstrap.css' %}" rel="stylesheet">
<link href="{% static 'css/login.css' %}" rel="stylesheet"/>
<title>登录</title>
</head>
<body>
<div class="container">
<div class="col">
<form class="form-login" action="/login/" method="post">
<h3 class="text-center">欢迎登录</h3>
<div class="form-group">
<label for="id_username">用户名:</label>
<input type="text" name='username' class="form-control" id="id_username" placeholder="Username"
autofocus required>
</div>
<div class="form-group">
<label for="id_password">密码:</label>
<input type="password" name='password' class="form-control" id="id_password" placeholder="Password"
required>
</div>
<div>
<a href="/register/" class="text-success ">
<ins>新用户注册</ins>
</a>
<button type="submit" class="btn btn-primary float-right">登录</button>
</div>
</form>
</div>
</div> <!-- /container -->
<!-- Optional JavaScript -->
<!-- jQuery first, then Popper.js, then Bootstrap JS -->
<script src="{% static 'js/jquery.min.js' %}"></script>
<script src="{% static 'js/popper.js' %}"></script>
<script src="{% static 'js/bootstrap.min.js' %}"></script>
</body>
</html>
最后附上截图
print_r('点个赞吧');
var_dump('点个赞吧');
NSLog(@"点个赞吧!")
System.out.println("点个赞吧!");
console.log("点个赞吧!");
print("点个赞吧!");
printf("点个赞吧!\n");
cout << "点个赞吧!" << endl;
Console.WriteLine("点个赞吧!");
fmt.Println("点个赞吧!")
Response.Write("点个赞吧");
alert(’点个赞吧’)