我对django中的模态有点问题。
我有一个调用id的链接,id是一个模态。但是,模态并不是开放的。我很确定这种情况正在发生,因为链接位于"自动"形式,但我是django和python的新手,所以我不知道。
代码是:
{% block body %}
<div class="col-lg-12 page-content">
<h1 class="content-title">Meus Dados</h1>
<hr class="star-light">
<div class="form-content">
<form class="form-horizontal" method = 'POST' action="/user/edituser/">
{% csrf_token %}
{% for field in form_user %}
{% bootstrap_field field exclude="password,repeat_password" %}
{% endfor %}
<div class="button-div">
<a class="btn btn-info btn-block btn-password" href="#change-password"
data-toggle="modal">Alterar senha</a>
{% buttons %}
<button class="btn btn-success btn-block btn-edit" type = 'submit'>Salvar Dados</button>
{% endbuttons %}
</div>
</form>
<a class="btn btn-danger btn-block btn-delete" href="/user/delete" name="delete">Excluir minha conta</a>
</div>
</div>
<div class="modal hide" id="change-password">
<div class="modal-header">
<button class="close" data-dismiss="modal">×</button>
<p class="modal-title" id="myModalLabel">Change Password</p>
</div>
<div class="modal-body">
<div class="row">
<div class="modal-col col-sm-12">
<div class="well">
<form method="post" id="passwordForm">
<input type="password" class="input-lg form-control" name="password1"
id="password1" placeholder="New Password">
<input type="password" class="input-lg form-control" name="password2"
id="password2" placeholder="Repeat Password">
</form>
</div>
</div>
</div>
</div>
<div class="modal-footer">
<a href="#" class="btn btn-success btn-bloc">Alterar Senha</a>
</div>
</div>
{% endblock %}
有任何疑问,请问。 感谢。
答案 0 :(得分:0)
<a class="btn btn-info btn-block btn-password" href="#change-password" data-toggle="modal">Alterar senha</a>
除了data-target
之外,您还需要data-toggle
个属性。 http://getbootstrap.com/javascript/#live-demo
答案 1 :(得分:0)
尝试将标签“a”更改为
中的“按钮”标签<a class="btn btn-info btn-block btn-password" href="#change-password"
data-toggle="modal">Alterar senha</a>
并隐藏淡入
<div class="modal hide" id="change-password">
答案 2 :(得分:0)
将您的<a>
标记更改为以下内容:
<a class="btn btn-info btn-block btn-password" href="#"
data-toggle="modal" data-target="#change-password">Alterar senha</a>
至少这是我在Django模板中的做法。我认为 @souldeux 试图说,你需要使用data-target
属性来指定模态本身,而不是href
;在这种情况下,我通常只使用#
。
另外,请确保您不仅要加载引导程序css代码,还要加载引导程序js库。换句话说,请确保模板中包含以下内容(或等效内容):
<!-- Latest compiled and minified JavaScript (at the time of this post) -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
除了你的css:
<!-- Latest compiled and minified CSS (at the time of this post) -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
我认为你已经拥有了,因为否则事情看起来会很奇怪。