简体   繁体   English

使用URL语法发送参数

[英]Send parameters using URL syntax

I'm trying to use the audio player Timeside in Django 1.5. 我正在尝试在Django 1.5中使用音频播放器Timeside。 JavaScript function that handles loading the player receives this set of parameters, 处理播放器加载的JavaScript函数会接收到这组参数,

loadplayer.js loadplayer.js

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

In my template is the following script that handles launch 在我的模板中是处理启动的以下脚本

{% 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%}

URLs are configured as follows 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"),

This worked in Django 1.4, attempt to update for be used in version 1.5. 这在Django 1.4中有效,尝试更新以在1.5版中使用。 The problem is that I can not send the parameter MP3 here 问题是我无法在此处发送参数MP3

"{% url 'item-export' item.public_id,"mp3" %}", 

the view item_export is like this: 视图item_export如下所示:

def item_export(self, request, public_id, extension):

When the player loads I get the following error: 当播放器加载时,出现以下错误:

Could not parse the remainder: ',' from 'pista.public_id,'

Which is the correct syntax for this on Django 1.5? 在Django 1.5上,哪种语法正确?

Using the name and equal solved this step 使用名字和等于解决了这一步

{% url 'item-export' public_id=item.public_id extension="mp3" %}

Seems like it is working but I have a new error: 似乎正在运行,但出现了新错误:

NoReverseMatch at /pista/1/

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

I do not want to answer my own question but I've been searching and trying a lot and I found the solution. 我不想回答我自己的问题,但是我一直在搜索并尝试了很多,然后找到了解决方案。

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

The first quotes refer to the name of the url(everybody know), item.id can be variable depends on the object, but if I write it in quotes it will be a string of characters wich not accept any value beyond which we assign. 第一个引号是指url的名称(每个人都知道),item.id可以是可变的,取决于对象,但是如果我用引号将其写入,它将是一个字符串,该字符串不接受我们指定的其他值。 That's my conclusion after 5 hours of searching but I can be wrong :) hope u understand me 这是经过5个小时的搜索得出的结论,但我可能是错的:)希望您能理解我

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM