Python web模版Django-23 用Bootstraps上的examples/singin改造我的index.html

本文介绍如何利用Bootstrap快速修改并优化登录页面的设计与功能,包括调整样式、修正路径及解决布局问题。

        前面尝试用Bootstraps页面改造了一下button,还是成功的。现在是用最快的速度改造整个index.html,步骤如下。

step1: 在Bootstraps官网上找到一个singin的example (https://v3.bootcss.com/examples/signin/),如下:


step2: 将其代码copy下来,覆盖到index.html,然后进行改造。

<!DOCTYPE html>
<html lang="zh-CN">
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <!-- 上述3个meta标签*必须*放在最前面,任何其他内容都*必须*跟随其后! -->
    <meta name="description" content="">
    <meta name="author" content="">
    <link rel="icon" href="../../favicon.ico">

    <title>Signin Template for Bootstrap</title>

    <!-- Bootstrap core CSS -->
    <link href="https://cdn.bootcss.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">

    <!-- IE10 viewport hack for Surface/desktop Windows 8 bug -->
    <link href="../../assets/css/ie10-viewport-bug-workaround.css" rel="stylesheet">

    <!-- Custom styles for this template -->
    <link href="signin.css" rel="stylesheet">

    <!-- Just for debugging purposes. Don't actually copy these 2 lines! -->
    <!--[if lt IE 9]><script src="../../assets/js/ie8-responsive-file-warning.js"></script><![endif]-->
    <script src="../../assets/js/ie-emulation-modes-warning.js"></script>

    <!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
    <!--[if lt IE 9]>
      <script src="https://cdn.bootcss.com/html5shiv/3.7.3/html5shiv.min.js"></script>
      <script src="https://cdn.bootcss.com/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
  </head>

  <body>

    <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 -->
    <script src="../../assets/js/ie10-viewport-bug-workaround.js"></script>
  </body>
</html>

Step3:  将其代码修一下,实现原来index.html的逻辑和UI。

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <!-- 上述3个meta标签*必须*放在最前面,任何其他内容都*必须*跟随其后! -->
    <meta name="description" content="">
    <meta name="author" content="">
    <link rel="icon" href="../../favicon.ico">

    <title>Django Page</title>

    <!-- Bootstrap core CSS -->
    <link href="https://cdn.bootcss.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">

    <!-- IE10 viewport hack for Surface/desktop Windows 8 bug -->
    <link href="../../assets/css/ie10-viewport-bug-workaround.css" rel="stylesheet">

    <!-- Custom styles for this template -->
    <link href="signin.css" rel="stylesheet">

    <!-- Just for debugging purposes. Don't actually copy these 2 lines! -->
    <!--[if lt IE 9]><script src="../../assets/js/ie8-responsive-file-warning.js"></script><![endif]-->
    <script src="../../assets/js/ie-emulation-modes-warning.js"></script>

    <!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
    <!--[if lt IE 9]>
      <script src="https://cdn.bootcss.com/html5shiv/3.7.3/html5shiv.min.js"></script>
      <script src="https://cdn.bootcss.com/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
  </head>

  <body>

    <div class="container">

      <form class="form-signin" action="/login_action/" method="post">
        <h2 class="form-signin-heading">发布会管理</h2>
        <label for="inputUsername" class="sr-only">username</label>
        <input type="text" id="inputUsername" name="username" class="form-control" placeholder="username" required autofocus>
        <label for="inputPassword" class="sr-only">password</label>
        <input type="password" id="inputPassword" name="password" class="form-control" placeholder="password" required>
     <!--这个checkbox的代码,我直接删除了-->
        <button class="btn btn-lg btn-primary btn-block" type="submit" id="btn">登录</button>
         {{wronglyInput}}<br>
         {% csrf_token %}
      </form>

    </div> <!-- /container -->


    <!-- IE10 viewport hack for Surface/desktop Windows 8 bug -->
    <script src="../../assets/js/ie10-viewport-bug-workaround.js"></script>
  </body>
</html>

step4: 看看效果,感觉还是有些问题,编辑框和登录按钮太宽了。


step5: 用开发工具查一下,发现有两个js和css文件取的路径不对,我们本地是没有的; 查一下example的,有现成的路径,将这些绝对路径直接copy到index.html中,替换原来的相对路径。





step6: 替换路径

 将<link href="signin.css" rel="stylesheet">

 替换为 <link href="https://v3.bootcss.com/examples/signin/signin.css" rel="stylesheet">

将<script src="../../assets/js/ie-emulation-modes-warning.js"></script>
替换为<script src="https://v3.bootcss.com/assets/js/ie-emulation-modes-warning.js"></script>
<script src="../../assets/js/ie10-viewport-bug-workaround.js"></script>
替换为<script src="https://v3.bootcss.com/assets/js/ie10-viewport-bug-workaround.js"></script>
<link href="../../assets/css/ie10-viewport-bug-workaround.css" rel="stylesheet">
替换为<link href="https://v3.bootcss.com/assets/css/ie10-viewport-bug-workaround.css" rel="stylesheet">

step7: 刷新index.html,看看效果,这次对了。


Django 4.1.2 中遇到模板 `dist/spa/index.html` 不存在的异常,可通过以下方法解决: ### 检查模板路径配置 在 Django 的 `settings.py` 文件中,`TEMPLATES` 配置项里有 `DIRS` 列表,用于指定模板文件的搜索路径。确保 `dist/spa` 路径已正确添加到 `DIRS` 列表中。示例如下: ```python TEMPLATES = [ { 'BACKEND': 'django.template.backends.django.DjangoTemplates', 'DIRS': [BASE_DIR / 'dist/spa'], # 确保此处路径正确 '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', ], }, }, ] ``` ### 检查文件实际存在情况 要保证 `dist/spa/index.html` 文件确实存在于项目目录中。可使用以下命令检查文件是否存在: ```bash ls dist/spa/index.html ``` 若文件不存在,需确认文件是否生成或者是否被误删除。 ### 检查文件权限 确保 Django 应用有足够的权限访问 `dist/spa/index.html` 文件。可使用以下命令修改文件和目录的权限: ```bash chmod -R 755 dist/spa ``` ### 检查模板加载方式 若使用的是 `render` 函数加载模板,要确保模板名称正确。示例如下: ```python from django.shortcuts import render def index(request): return render(request, 'index.html') # 确保模板名称与实际文件名一致 ``` ### 检查静态文件配置 若 `dist/spa` 包含静态文件,要确保静态文件配置正确。在 `settings.py` 中配置 `STATICFILES_DIRS`: ```python STATICFILES_DIRS = [ BASE_DIR / 'dist/spa', # 确保此处路径正确 ] ```
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值