【问题标题】:Django: How do I remove the ending "?" from the URLDjango:如何删除结尾“?”从网址
【发布时间】:2021-03-23 11:59:51
【问题描述】:

我需要删除“?”在我的网址末尾:

urls.py

urlpatterns = [path("map_fslis_top/totals/<int:fstype_id>", views.edit_totals, name="edit_totals"),]

view.py

def edit_totals(request, fstype_id):
    # Some code...
    return render(request, "DataMech/totals.html", {
        'fstype': fstype,
        'typefslis': typefslis,
        'totals': totals,
    })

html 触发器

<button href="{% url 'edit_totals' fstype_id=fstype.id %}" class="btn btn-primary" class="form-control" type="submit" value="submit">Totals</button>

生成页面的网址:http://127.0.0.1:8000/map_fslis_top/totals/1?

我该如何摆脱那个丑陋的“?”在 URL 的末尾?

【问题讨论】:

  • 您可以在 url 格式的末尾添加一个美元符号 - &lt;int:fstype_id&gt;$

标签: django django-urls


【解决方案1】:

添加 / 似乎有效,但它只是替换了 ?符号。不要消除它。

我找到了解决方案。只需将按钮包装在“a”标签中,它似乎就可以工作。不 ?或 URL 末尾的任何其他符号。

<a href="{% url 'edit_totals' fstype_id=fstype.id %}"><button class="btn btn-primary" class="form-control">Totals</button></a>

【讨论】:

    猜你喜欢
    • 2013-01-18
    • 1970-01-01
    • 1970-01-01
    • 2013-05-17
    • 2016-04-09
    • 1970-01-01
    • 2021-03-17
    • 2020-08-13
    • 1970-01-01
    相关资源
    最近更新 更多