我爱编程

Pythone入门到实践-学习笔记-Day11

2018-04-11  本文已影响0人  DKJImmy

设置应用程序的样式并对其进行部署

一、应用程序django-bootstrap3

BOOTSTRAP3={
  'include_jquery':True,
}

二、使用Bootstrap设置项目样式

#加载django-bootstrap3中的模板标签集
{% load bootstrap3 %}
<!DOCTYPE html>
<html lang='en'>
#head头部不包含任何内容,将正确显示页面所需的信息告诉浏览器
    <head>
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="viewreport" content="width=device-width,inital-scale=1">
        <title>Learning Log</title>
    </head>
#包含Bootstrap样式文件
    {% bootstrap_css %}
#启用在页中使用的所有交互行为
    {% bootstrap_javascript %}
#HTML文件的主体包含用户将在页面上看到的内容
    <body>
#导航
        <nav class="navbar navbar-default navbar-static-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">
                </button>
                <a class="navbar-brand" href="{% url 'learning_logs:index' %}">Learning Log</a>
            </div>
            <div id="navbar" class="navbar-collapse collapse">
                <ul class="nav navbar-nav">
                    <li><a href="{% url 'learning_logs:topics' %}">Topics</a></li>
                </ul>
                <ul class="nav navbar-nav navbar-right">
                    {% if user.is_authenticated %}     
                        Hello, {{ user.username }}.   
                        <a href="{% url 'users:logout' %}">logout</a>
                    {% else %}     
                        <a href="{% url 'users:register' %}">register</a>   
                        <a href="{% url 'users:login' %}">log in</a>   
                    {% endif %} 
                </ul>
            </div>
        </nav>
#页面主要部分
        <div class="container">
            <div class="page-header">
                {% block header %}{% endblock header %}
            </div>
            <div>
                {% block content %}{% endblock content %}
            </div>
    </body> 
</html>
{% extends "learning_logs/base.html" %}
{% block header %}
    <div class="jumbotron">
        <h1>Track your learing</h1>
    </div>
{% endblock header %}

{% block content %}
    <h2>
        <a href="{% url 'users:register' %}">Register an account</a> 
        to make your own Learning Log,and list the topoic you're learning about.
    <h2>
        Whenever you learn something new about a topic,make an entry summarizing what you're learned.
    </h2>
{% endblock content%}
运行结果
{% extends "learning_logs/base.html" %}
{% load bootstrap3 %}

{% block header %}
    <h2>Log in to your account</h2>
{% endblock header%}

{% block content %}
    {% if form.errors %}
    <p>Your name and password didn't match.Please try again</p>
    {% endif %}
    
    <form class="form" method="post" action="{% url 'users:login' %}">
        {% csrf_token %}
        {% bootstrap_form form %}
        
        {% buttons %}
        <button class="bnt btn-primary" name="submit">login</button>
        {% endbuttons %}
        <input type="hidden" name="next" value="{% url 'learning_logs:index' %}" />
    </form>
{% endblock content %}
运行结果
上一篇 下一篇

猜你喜欢

热点阅读