django中模板继承中的块周围的if语句

时间:2018-06-21 08:39:15

标签: html django python-3.x

我的网站上的客户和银行家有两种类型的用户

我不希望银行家访问客户的仪表板,反之亦然。

所以我使用了django-role-permissions库,并在注册时为每个用户赋予了角色,效果很好。

现在,我想授予每个页面授权,并指定哪个用户可以访问哪个页面。我希望如果银行家登录并尝试打开客户仪表板,应该怎么办?

所以我更改了customer_dashboard并应用了如果用户是银行家显示错误,但是由于我使用模板继承,因此错误页面显示了页眉和页脚,但我不希望这样。我想要一个清晰的错误消息,没有别的,所以我尝试了这个-

  

我的customer_dashboard.html文件

<!DOCTYPE html>
{% extends "base.html" %}
{% load permission_tags %}
{% if user|has_role:'banker' %}
  {% block main_block %}
    <h1>error!!</h1>
  {% endblock main_block%}
{% else %}
  {% block body_block %}
    <div class="container">
      <div class="jumbotron">
        <h1>Hello! Wellcome to Your Personal DashBoard</h1>
        <h3>now you can check your credit score!</h3>
      </div>
    </div>
  {% endblock body_block %}
{% endif %}
  

还有我的base.html文件

<!DOCTYPE html>
{% load staticfiles %}
{% load permission_tags %}
<html>
  <head>
    <meta charset="utf-8">
    <title></title>
    <!-- Latest compiled and minified CSS -->
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
    <link rel="stylesheet" href="http://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.6.3/css/font-awesome.min.css">
    <link href="https://fonts.googleapis.com/css?family=Pacifico" rel="stylesheet">
    <link href="https://fonts.googleapis.com/css?family=Roboto" rel="stylesheet">
    <link rel="stylesheet" href="{% static "css/base_styling.css" %}"/>
  </head>

  <body>
    {% block main_block %}

    <!-- NAVBAR HEADER-->
    <nav class="navbar navbar-dark">
      <div class="container-fluid">
        <div class="navbar-header">
          <a class="navbar-brand" href="{% url 'home' %}">Credit Solutions</a>
        </div>
        <div class="collapse navbar-collapse" id="navbarNavAltMarkup">
          {% if user.is_authenticated %}
              <div class="nav navbar-nav">
                <a class="nav-item nav-link" id="score" href="#">Eligibility Score</a>
                <a class="nav-item nav-link" id="score" href="#">Credit Score</a>
              </div>
          {% endif %}
          <div class="nav navbar-nav navbar-right">
            <a class="nav-item nav-link" href="{% url 'howitworks' %}">How It Works</a>
            <a class="nav-item" id="line">|</a>
            <a class="nav-item nav-link" href="{% url 'helpcenter' %}">Help Center</a>
            <a class="nav-item" id="line">|</a>

            {% if user.is_authenticated %}
                <div class="nav-item dropdown">
                  <a class="dropbtn">Wellcome</a>
                  <div class="dropdown-content" style="Right:0;>
                    <a href="#"></a>
                    <a href="#">User Profile</a>
                    <a href="#">Change Password</a>
                    <a href="{% url 'personal:logout' %}">Logout</a>
                  </div>
                </div>

            {% else %}
              <div class="nav-item dropdown">
                <a class="dropbtn">Log In</a>
                <div class="dropdown-content" style="Right:0;>
                  <a href="#"></a>
                  <a href="{% url 'personal:login' %}">Personal</a>
                  <a href="{% url 'business:login' %}">Business</a>
                </div>
              </div>
              <a class="nav-item" id="line">|</a>

              <div class="nav-item dropdown" >
                <a class="dropbtn">Sign Up</a>
                <div class="dropdown-content" style="right:0;>
                  <a href="#"></a>
                  <a href="{% url 'personal:signup' %}">Personal</a>
                  <a href="{% url 'business:signup' %}">Business</a>
                </div>
              </div>
            {% endif %}

          </div>
        </div>
      </div>
    </nav>
    <!-- NAVBAR HEADER ENDS -->


        {% block body_block %}

        {% endblock body_block%}



    <!-- NAVBAR FOOTER-->
    <div class="content">
    </div>
    <footer id="myFooter">
        <div class="container">
            <div class="row">
                <div class="col-sm-3">
                    <h5>Get started</h5>
                    <ul>
                        <li><a href="{% url 'home' %}">Home</a></li>
                        <li><a href="{% url 'personal:signup' %}">Sign up</a></li>
                    </ul>
                </div>
                <div class="col-sm-3">
                    <h5>About us</h5>
                    <ul>
                        <li><a href="#">Company Information</a></li>
                        <li><a href="#">Contact us</a></li>
                        <li><a href="#">Reviews</a></li>
                    </ul>
                </div>
                <div class="col-sm-3">
                    <h5>Support</h5>
                    <ul>
                        <li><a href="{% url 'helpcenter' %}">FAQ</a></li>
                        <li><a href="{% url 'helpcenter' %}">Help desk</a></li>
                        <li><a href="https://www.epicgames.com/fortnite/forums">Forums</a></li>
                    </ul>
                </div>
                <div class="col-sm-3 info">
                    <h5>Information</h5>
                    <p> Everyone deserves to feel confident about their finances. Our job is to give you the tools, the education and the opportunities you need to make real, meaningful progress.Thinking about your finances can be frustrating, but we're working to make the process simpler and easier to understand for over 75 million Credit Karma members.</p>
                </div>
            </div>
        </div>
        <div class="second-bar">
           <div class="container">
                <h2 class="logo"><a href="{% url 'home' %}"> CREDIT SOLUTIONS </a></h2>
                <div class="social-icons">
                    <a href="https://twitter.com/" class="twitter"><i class="fa fa-twitter"></i></a>
                    <a href="https://facebook.com/" class="facebook"><i class="fa fa-facebook"></i></a>
                    <a href="https://plus.google.com/" class="google"><i class="fa fa-google-plus"></i></a>
                </div>
            </div>
        </div>
    </footer>
    <!-- NAVBAR FOOTER ENDS -->
    {% endblock main_block %}
  </body>
</html>

但是现在当我运行它时,它总是显示错误的天气,银行家登录或客户登录。 请任何人可以帮助我

0 个答案:

没有答案