gpt4 book ai didi

python - 使用URL语法发送参数

转载 作者:行者123 更新时间:2023-12-03 02:19:19 24 4
gpt4 key购买 nike

我正在尝试在Django 1.5中使用音频播放器Timeside。处理播放器加载的JavaScript函数会接收到这组参数,

loadplayer.js

loadPlayer function (analizerUrl, soundUrl, soundImgSize, itemId, visualizers,   CurrentUserName, isStaffOrSuperuser)

在我的模板中是处理启动的以下脚本
{% If item.file %}
loadPlayer('{% url 'item-analyze-xml' item.public_id %}',
"{% url 'item-export' item.public_id,"mp3" %}", undefined, '{{item.id}}', visualizers,
CURRENT_USER_NAME, //undefined if !user.is_authenticated
true); //true because superuser
{% Endif%}

URL配置如下
url(r'^archives/items/download/(?P<public_id>[A-Za-z0-9._-]+)\.(?P<extension>'
+ export_extensions + ')$',
item_view.item_export,
name="item-export"),

url(r'^archives/items/(?P<public_id>[A-Za-z0-9._-]+)/analyze/xml/$',
item_view.item_analyze_xml,
name="item-analyze-xml"),

这在Django 1.4中有效,尝试更新以在1.5版中使用。问题是我无法在此处发送参数MP3
"{% url 'item-export' item.public_id,"mp3" %}", 

View item_export如下所示:
def item_export(self, request, public_id, extension):

当播放器加载时,出现以下错误:
Could not parse the remainder: ',' from 'pista.public_id,'

在Django 1.5上,哪种语法正确?

使用名字和等于解决了这一步
{% url 'item-export' public_id=item.public_id extension="mp3" %}

似乎正在运行,但出现了新错误:
NoReverseMatch at /pista/1/

Reverse for 'item-analyze-xml' with arguments '()' and keyword arguments '{u'public_id': ''}' not found.

最佳答案

我不想回答我自己的问题,但是我一直在搜索并尝试了很多,然后找到了解决方案。

{% Url 'impromusic-item-export' item.id 'mp3'%}

第一个引号是指url的名称(每个人都知道),item.id可以是可变的,取决于对象,但是如果我用引号将其写入,它将是一个字符串,该字符串不接受我们指定的其他值。
这是我经过5个小时的搜索得出的结论,但是我可能是错的:)希望你能理解我

关于python - 使用URL语法发送参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15773676/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com