【问题标题】:Django website - make button link to a different appDjango 网站 - 将按钮链接到不同的应用程序
【发布时间】:2017-07-18 19:52:18
【问题描述】:

我正在尝试制作一个按钮,当您单击它时链接到另一个应用程序。

由于某种原因,这可行:

<a href="{% url 'ridesharing:ride-list' %}" target="blank">Find a ride</a>

但这不是:

<button type="button" class="btn btn-xl" style=" border-color: rgb(2,132,69); background-color: rgb(2,132,69); color: rgb(246,246,247); font-family: Verdana;font-size: large" href="{% url 'ridesharing:ride-list' %}">Find a ride</button>

我使用按钮是因为我喜欢如何自定义它的外观。如何获得链接到正确应用的按钮。

【问题讨论】:

  • 这不是一个 django 问题。这是一个 CSS 问题。要使用的正确元素是 A 而不是 BUTTON。你只需要正确地设计它。投资像 bootstrap 这样的框架。这将使您的生活更轻松

标签: html css django-templates


【解决方案1】:

让按钮提交表单,其 URL 为表单的action

<form action="{% url 'ridesharing:ride-list' %}">
  <button type="submit" class="btn btn-xl" style=" border-color: rgb(2,132,69); background-color: rgb(2,132,69); color: rgb(246,246,247); font-family: Verdana;font-size: large">Find a ride</button>
</form>

或者添加一个事件监听器/处理程序来改变window.location.href

<button type="button" class="btn btn-xl" style=" border-color: rgb(2,132,69); background-color: rgb(2,132,69); color: rgb(246,246,247); font-family: Verdana;font-size: large" onclick="window.location.href='{% url 'ridesharing:ride-list' %}'">Find a ride</button>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2010-09-22
    • 1970-01-01
    • 2020-07-26
    • 2014-12-29
    • 1970-01-01
    • 2018-09-15
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多