开发者

how to include an asterisk a url within Django?

开发者 https://www.devze.com 2023-01-31 10:20 出处:网络
I have the following code in my Django template: <a href=\"{% url myapp.views.myview foobar %}\">

I have the following code in my Django template:

<a href="{% url myapp.views.myview foobar %}">

so, what's the right way to开发者_如何学JAVA handle the situation where "foobar" contains an asterisk (for example, "*1234")? At the moment, Django is throwing this error:

Caught NoReverseMatch while rendering: Reverse for 'myapp.views.myview.myview' 
with arguments '(u'*86743',)' and keyword arguments '{}' not found.


Commonly, You'd see this if you're specifying a url rule with a \w regex. For example:(r'^myview/(?P<myparam>\w.+)/$', 'myview') would cause this. Broadening the regex a bit to allow the ampersand should cure your ills.


Make sure that one of the entries in your urlconf actually matches the arguments you pass. If you only allow digits ([0-9]+) then an asterisk won't match.

0

精彩评论

暂无评论...
验证码 换一张
取 消