【问题标题】:how to add values from view to url in django如何在 django 中将视图中的值添加到 url
【发布时间】:2021-10-06 06:01:57
【问题描述】:

我必须将视图中的值提供给 url,就像名称是视图中的值一样: 我怎样才能做到这一点

【问题讨论】:

  • 请包含代码,而不是代码图像meta.stackoverflow.com/questions/285551/…
  • 明确要达到什么
  • @WillemVanOnsem 对此我深表歉意..下次每当我提出问题时,我都会上传代码而不是图像..请投票支持我的问题
  • 我没有否决您的问题。但由于链接问题中提到的原因,使用代码图像只是“没有(真正)完成”。

标签: python-3.x django django-models django-rest-framework django-templates


【解决方案1】:

在你看来

def your_view(request):
    context = {}
    .
    .
    .
    context['name'] = value_you want_to_use
    return render(request, url_to_template, context)

现在在您的模板中,您可以将值用作

{{name}}

【讨论】:

  • 获取错误上下文未定义
  • @AshutoshAnand 立即行动。
  • 你在 FB 或 INSTA 或 DISCORD 上不工作
  • 用你的观点更新你的问题,还有更多的代码,你现在面临什么错误?
  • 现在看我已经给了完整的ss
【解决方案2】:

只需删除 {% static “covapp/img/“{{name}}”.jpg” %} 并简单地给出 src EG 的路径

src="./covapp/img/{{name}}.jpg" 

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-09-22
    • 1970-01-01
    • 1970-01-01
    • 2017-11-06
    • 1970-01-01
    • 2014-11-14
    • 2022-01-24
    • 1970-01-01
    相关资源
    最近更新 更多