前提需要:把框架那些配置啥的都写好
用bootstrap(别人写好的样式)把界面显示的好看点
一、app02/views.py
from django.shortcuts import render,redirect,HttpResponse# Create your views here.def login(request): if request.method=='GET': return render(request,'login.html') else: name=request.POST.get('name') password=request.POST.get('password') print(name) print(password) if name=='ayca' and password=='123': # return redirect('http://www.baidu.com') # 登录成功重定向到index页面 return redirect('/index') else: return HttpResponse('用户名密码错误')def index(request): return render(request,'index2.html')
二、settings.py
import os# BASE_DIR:项目根路径BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))# SECRET_KEY:密钥,项目中默认的一些加密用它(不需要关注,可以改,但是不能删)SECRET_KEY = 'dk_'# DEBUG:调试模式,开,开发阶段是true,上线阶段把它设成false# 设置成开报错信息更完善DEBUG = True# ALLOWED_HOSTS:上线阶段使用,允许谁访问ALLOWED_HOSTS = ['*']# INSTALLED_APPS 项目所有的app,新建的app要在里面注册INSTALLED_APPS = [ 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', # 'app01.apps.App01Config', 'app01', # 'app02.apps.App02Config', # 'app100' #]# MIDDLEWARE 中间件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 根路由是哪个文件,根路由的位置可以变ROOT_URLCONF = 'day60.urls'# TEMPLATES 模板文件存放路径(如果使用django-admin创建的项目,需要手动配,否则找不到)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 wsgi服务器使用的是哪个WSGI_APPLICATION = 'day60.wsgi.application'# DATABASES 数据库链接配置DATABASES = { 'default': { 'ENGINE': 'django.db.backends.sqlite3', 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'), }}# 不用管(内置app相关)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', },]# 国际化相关,语言,时区LANGUAGE_CODE = 'en-us'TIME_ZONE = 'UTC'USE_I18N = TrueUSE_L10N = TrueUSE_TZ = True# 静态文件配置相关STATIC_URL = '/static/'# 再配一个STATICFILES_DIRS=列表(列表内写路径),单词一个字母都不能错STATICFILES_DIRS=[ os.path.join(BASE_DIR,'static'),]
三、day60/urls.py
from django.conf.urls import urlfrom django.contrib import adminfrom app01 import viewsfrom app02 import views as views2# urlpatterns列表,列表内放了url函数的执行结果# 使用很简单,复制一行,改一下第一个参数(正则表达式),第二个参数是视图函数内存地址urlpatterns = [ url(r'^admin/', admin.site.urls), # 在内部,请求来了,路径匹配成功,内部自动调用index(request),把request传入 # url(r'^index', views.index), # 登录小案例 url(r'^login', views2.login), url(r'^index', views2.index),]
四、static/bootstrap
把已下载好的bootstrap直接拉入,并导入index2里
五、直接导入已下载好的或引用jQurey地址
jQuery相关网站官网 https://jquery.com/文档API: http://jquery.cuishifeng.cn/index.html#直接打开复制粘贴到自己创建的.js / .min.js文件下BootCDN jQuery各个版本地址: https://www.bootcdn.cn/jquery/#方式一:本地引入<script src="jquery-3.5.1.min.js"></script><script> //注意,一定在引入jQuery之后,再使用jQuery提供的各种操作</script>#方式二:直接使用CDN<script src="https://cdn.bootcss.com/jquery/3.5.1/jquery.js"></script><script> code...</script>
六、templates\index2.html
<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8"> <link rel="stylesheet" href="http://www.cnblogs.com//static/bootstrap/css/bootstrap.css"> <script src="http://www.cnblogs.com//static/js/jquery.min.js"></script> <title>首页</title></head><body> <nav class="navbar navbar-inverse navbar-fixed-top"> <div class="container"> <div class="navbar-header"> <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar"> <span class="sr-only">导航</span> <span class="icon-bar"></span> <span class="icon-bar"></span> <span class="icon-bar"></span> </button> <a class="navbar-brand" href="#">Project name</a> </div> <div id="navbar" class="navbar-collapse collapse"> <form class="navbar-form navbar-right"> <div class="form-group"> <input type="text" placeholder="Email" class="form-control"> </div> <div class="form-group"> <input type="password" placeholder="Password" class="form-control"> </div> <button type="submit" class="btn btn-success">Sign in</button> </form> </div><!--/.navbar-collapse --> </div> </nav> <!-- Main jumbotron for a primary marketing message or call to action --> <div class="jumbotron"> <div class="container"> <h1>标题1 自己写</h1> <p>This is a template for a simple marketing or informational website. It includes a large callout called a jumbotron and three supporting pieces of content. Use it as a starting point to create something more unique.</p> <p><a class="btn btn-primary btn-lg" href="#" role="button">Learn more »</a></p> </div> </div> <div class="container"> <!-- Example row of columns --> <div class="row"> <div class="col-md-4"> <h2>Heading</h2> <p>Donec id elit non mi porta gravida at eget metus. Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh, ut fermentum massa justo sit amet risus. Etiam porta sem malesuada magna mollis euismod. Donec sed odio dui. </p> <p><a class="btn btn-default" href="#" role="button">View details »</a></p> </div> <div class="col-md-4"> <h2>Heading</h2> <p>Donec id elit non mi porta gravida at eget metus. Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh, ut fermentum massa justo sit amet risus. Etiam porta sem malesuada magna mollis euismod. Donec sed odio dui. </p> <p><a class="btn btn-default" href="#" role="button">View details »</a></p> </div> <div class="col-md-4"> <h2>Heading</h2> <p>Donec sed odio dui. Cras justo odio, dapibus ac facilisis in, egestas eget quam. Vestibulum id ligula porta felis euismod semper. Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh, ut fermentum massa justo sit amet risus.</p> <p><a class="btn btn-default" href="#" role="button">View details »</a></p> </div> </div> <hr> <footer> <p>© 2016 Company, Inc.</p> </footer> </div> <!-- /container --></body></html>index2
七、templates\login.html
<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8"> <link rel="stylesheet" href="http://www.cnblogs.com//static/bootstrap/css/bootstrap.css"> <title>Title</title></head><body><div class="row"> <div class="col-md-6 col-md-offset-3"> <h1 class="text-center">登录功能</h1> <form action="" method="post"> <div class="form-group"> <label for="">用户名:</label> <input type="text" name="name" class="form-control"> </div> <div class="form-group"> <label for="">密码:</label> <input type="password" name="password" class="form-control"> </div> <div class="text-center"> <input type="submit" value="登录" class="btn btn-success"> </div> </form> </div></div></body></html>login
原文转载:http://www.shaoqun.com/a/477706.html
patpat:https://www.ikjzd.com/w/1079
腾邦:https://www.ikjzd.com/w/1382
yiqu:https://www.ikjzd.com/w/210
前提需要:把框架那些配置啥的都写好用bootstrap(别人写好的样式)把界面显示的好看点一、app02/views.pyfromdjango.shortcutsimportrender,redirect,HttpResponse#Createyourviewshere.deflogin(request):ifrequest.method=='GET':returnrender(r
acca:https://www.ikjzd.com/w/1370
upc:https://www.ikjzd.com/w/111
AB Tasty:https://www.ikjzd.com/w/2098
跨境电商运营技巧_如何打造店铺爆款商品_店铺订单少原因分析:https://www.ikjzd.com/home/120278
亚马逊新手店铺实操:https://www.ikjzd.com/tl/14596
没有评论:
发表评论