django - 如何将 url 参数传递给模板中的 url 标签
问题描述
我正在使用 Django 3.1
我已配置 URL,以便我可以在模板中正确使用以下内容:
<li><a href="{% url 'sitemember:profile' 'bobby' %}">{{ user.username }} </a></li>
其中 user.username 解析为 'bobby'
如何将变量传递user.username
给url()
标记,以便 URL 正确解析为:
https://localhost:/user/bobby(例如)
解决方案
您在{% url … %}
模板标签 [Django-doc]中指定:
<a href="{% url 'sitemember:profile' user.username %}">
推荐阅读
- java - com.fasterxml.jackson.databind.exc.MismatchedInputException,同时使用fastxml将json回复解析为对象
- android - 尝试在片段中重新加载方法
- json - react native react-native-geocoding地址不会渲染
- xml - XMLReader - 如何读取此元素/节点模式
- php - php中私有方法的继承和后期静态绑定
- dart - AngularDart 触摸和移动
- java - 无法在 android web 视图中从服务器下载文件
- matlab - 在MATLAB中为神经网络执行用户定义的卷积函数非常慢
- python - NLTK语言树遍历和提取名词短语(NP)
- xcode - 如何在 Xcode 中渲染具有半透明纹理的 3D 模型?