Django-初阶实例
2024-08-31 13:01:45
调用本地css文件的方法
setting.py里面的内容
import os # Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) # Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/2.2/howto/deployment/checklist/ # SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = '9ssccke32^tmaoq4rv_ccc&_2*emfq@vx#2g+-_xyo(c1@*tbo' # SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True ALLOWED_HOSTS = [] # Application definition INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
] MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
] ROOT_URLCONF = 'ServeProj.urls' TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(BASE_DIR, 'templates')]
,
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
] WSGI_APPLICATION = 'ServeProj.wsgi.application' # Database
# https://docs.djangoproject.com/en/2.2/ref/settings/#databases DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
}
} # Password validation
# https://docs.djangoproject.com/en/2.2/ref/settings/#auth-password-validators AUTH_PASSWORD_VALIDATORS = [
{
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
},
] # Internationalization
# https://docs.djangoproject.com/en/2.2/topics/i18n/ LANGUAGE_CODE = 'en-us' TIME_ZONE = 'UTC' USE_I18N = True USE_L10N = True USE_TZ = True # Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/2.2/howto/static-files/ STATIC_URL = '/static/'
#定义了 ip/static 是存放数据的文件夹
STATICFILES_DIRS=[
os.path.join(BASE_DIR,'static'), #相当于设置 ip/static这个数据文件夹 等同于 计算机内django工程文件夹的绝对路径/static
os.path.join(BASE_DIR,'static_img'), #相当于设置 ip/static这个数据文件夹 等同于 计算机内django工程文件夹的绝对路径/static_image
#以上就设置了如果浏览器找ip/static 那就去 django工程文件夹的绝对路径/static 或者 django工程文件夹的绝对路径/static_image里面找
]
url.py里的内容
from django.contrib import admin
from django.urls import path
from django.shortcuts import HttpResponse,render def index(request):
#业务
res=HttpResponse('进来的页面时index') #返回自己想要的字符串
return res def sb(request):
return render(request,'sb.html') #返回自己想展示的网页 def login(request):
return render(request,'login.html') urlpatterns = [
path('admin/', admin.site.urls), #这一条是自带的
path('index/',index), #这一条是自己写的,如果输入index的界面那么跳转到index函数
path('sb/',sb), #这一条是自己写的,如果输入sb的界面那么跳转到sb函数
path('login/',login) #这一条是自己写的,如果输入sb的界面那么跳转到sb函数
]
login.html里的内容
<!DOCTYPE html>
<head>
<meta http-equiv="content-type" content="txt/html; charset=utf-8"/>
<!-- 控制网页为utf8编码,必须放在最前面 -->
<link rel="stylesheet" href="/static/bootstrap.css">
<!-- 这是bootcss的核心样式,用bootcss都要这个-->
<link href="/static/signin.css" rel="stylesheet">
<!-- 这是signin的核心样式,用bootcss都要这个--> <style>
.city {
float: left;
margin: 5px;
padding: 15px;
width: 300px;
height: 300px;
border: 1px solid black;
}
</style>
</head> <body>
<img src="/static/上课时间.jpg" alt="">
<img src="/static/遗传算法.png" alt="">
<!-- 引入图片,图放在django工程文件夹下面的static或者static_img里面-->
<div class="container">
<form class="form-signin">
<h2 class="form-signin-heading">Please sign in</h2>
<label for="inputEmail" class="sr-only">Email address</label>
<input type="email" id="inputEmail" class="form-control" placeholder="Email address" required="" autofocus="">
<label for="inputPassword" class="sr-only">Password</label>
<input type="password" id="inputPassword" class="form-control" placeholder="Password" required="">
<div class="checkbox">
<label>
<input type="checkbox" value="remember-me"> Remember me
</label>
</div>
<button class="btn btn-lg btn-primary btn-block" type="submit">Sign in</button>
</form>
</div> <!-- /container -->
<!-- IE10 viewport hack for Surface/desktop Windows 8 bug --> </body> </html>
按照用户输入的用户名和账号做出跳转链接
最新文章
- 使用极光/友盟推送,APP进程杀死后为什么收不到推送(转)
- Eclipse导入现有项目
- MySQL数据类型——数值类型
- git的几种回滚 git revert 和 git reset的区别
- Microsoft Office Excel 不能访问文件 的解决办法
- Machine Learning for hackers读书笔记(三)分类:垃圾邮件过滤
- .NET开源工作流RoadFlow-流程设计-流转条件设置(路由)
- Logstash 默认不处理一天前的文件
- Android使得手机拍照功能的发展(源共享)
- 从netty源码里拿到的关于http错误码,自己学习下
- python进阶(4):初始面向对象
- C语言_了解一下C语言中的四种存储类别
- protel dxp 2004安装与破解
- wildfly 10上使用最新的 Hibernate ORM OGM
- Python3-进程
- day37-多进程多线程二-锁
- 求Sn=a+aa+aaa+aaaa+aaaaa的前5项之和,其中a是一个数字
- vue属性值调方法
- 怎么解决BarTender因为未检测到IIS安装失败的问题
- Java连接GBase并封装增删改查