亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何使用超鏈接更改另一個頁面的標簽?

如何使用超鏈接更改另一個頁面的標簽?

翻翻過去那場雪 2023-07-05 15:25:35
我是 Django 新手,我想問一下是否可以使用另一個頁面的超鏈接來更改頁面的標簽。我想傳遞一個值,例如。'1' 并將其用作另一個模板的標簽。我可以使用超鏈接從一個頁面重定向到另一個頁面,但我不知道如何傳遞一些參數以供其他人使用。超鏈接的目的是告訴對方頁面它是為了某個值。這是我的超鏈接的代碼://It is a hyperlink with image.<a class="btn bgImg"  href="{% url 'trend_view'%}"></a>這是我認為的代碼:def stage_trend_view(request, value):    args={ val = value}    template = loader.get_template("Hole_Analyzer/trend_per_stage.html")    return HttpResponse(template.render(args, request))這是我想使用傳遞的值的模板:{% extends "base.html" %}{% load static %}{% block title %}Stages{% endblock %}{% block content-nav %} {% endblock content-nav %}{% block card_title %}Trend for Stage {{val}} {% endblock card_title %}    {% block content-Card %}      <div class="card-body">        <div class="row">          <p>This is Graphs and shits</p>        </div>      </div>    {% endblock content-Card %}{% block scripts %} {% endblock scripts %}這是 url.py:path(r'^trend/(?P<value>\d+)/$', stage_trend_view, name='trend_view')
查看完整描述

1 回答

?
撒科打諢

TA貢獻1934條經驗 獲得超2個贊

我將提到 GET 請求執行此操作的兩種方法。


一種方法是將其添加為 url 中的值:

超鏈接代碼相同:


<a class="btn bgImg"  href="{% url 'trend_view' value/variable_here %}"></a>

在代碼view.py中:


from django.template import Context

def stage_trend_view(request, value):

    args=Context({"val" : value})

    template = loader.get_template("Hole_Analyzer/trend_per_stage.html")

    return HttpResponse(template.render(args))

在 urls.py 中:


path('trend/<int:value>/', stage_trend_view, name='trend_view')

另一種方法是將其設置為 GET 參數

超鏈接代碼為:


<a class="btn bgImg"  href="{% url 'trend_view' %}?value={{value/vairable_here}}"></a>

在代碼views.py中:


from django.shortcuts import render

def stage_trend_view(request):

    value = request.GET.get('value')

    return render(request, 'Hole_Analyzer/trend_per_stage.html', {'val':value})

在 urls.py 中:


path('trend/', stage_trend_view, name='trend_view')

您可以自由選擇適合您的:)


查看完整回答
反對 回復 2023-07-05
  • 1 回答
  • 0 關注
  • 130 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號