0

Here is some text that isn't working when I pass it as a parameter for description (including the return character and url following it). I'm doing this in django.

partner/BuzzFeed/fXkqhhIlOtA/NY Yankees: 6 Essential Pieces of Postseason Memorabilia/The National Baseball Hall of Fame shows off 6 pieces of Yankees postseason memorabilia: a watch from the 1923 World Series; Babe Ruth's bat from the 1926 World Series; Yogi Berra's glove from Don Larsen's perfect game in 1956; the last out ball in the 1962 World Series; Derek Jeter's jersey from the 1996 World Series; Mariano Rivera's hat from the 2000 Subway Series. http://www.buzzfeed.com/sports/

urlpatterns = patterns('reserve.views',
    url(r'^partner/(?P<partner_name>[-\w]+)/$', 'partner_channel'),
    url(r'^partner/(?P<author>[-\w]+)/(?P<video>[-\w]+)/$', 'video_player'),
    url(r'^partner/(?P<author>[-\w]+)/(?P<video>[-\w]+)/(?P<title>.+)/(?P<desc>.+)/$', 'video_player'),
    url(r'^category/(?P<category>[-\w]+)/$', 'all_partners'),
    url(r'^admin/', include(admin.site.urls)),
)

How do I change the regex for the desc parameter to allow this?

edit:

Request URL Page not found (404):

http:/localhost:8000/partner/BuzzFeed/fXkqhhIlOtA/NY%20Yankees:%206%20Essential%20Pieces%20of%20Postseason%20Memorabilia/The%20National%20Baseball%20Hall%20of%20Fame%20shows%20off%206%20pieces%20of%20Yankees%20postseason%20memorabilia:%20a%20watch%20from%20the%201923%20World%20Series;%20Babe%20Ruth's%20bat%20from%20the%201926%20World%20Series;%20Yogi%20Berra's%20glove%20from%20Don%20Larsen's%20perfect%20game%20in%201956;%20the%20last%20out%20ball%20in%20the%201962%20World%20Series;%20Derek%20Jeter's%20jersey%20from%20the%201996%20World%20Series;%20Mariano%20Rivera's%20hat%20from%20the%202000%20Subway%20Series.%0A%0Ahttp://www.buzzfeed.com/sports/
4

3 回答 3

0

urlpatterns正在被覆盖(可能不正确)。您有两个匹配 'video_player' 但没有匹配 'desc' 的模式:

url(r'^partner/(?P<author>[-\w]+)/(?P<video>[-\w]+)/$', 'video_player'),
url(r'^partner/(?P<author>[-\w]+)/(?P<video>[-\w]+)/(?P<title>.+)/(?P<desc>.+)/$', 'video_player'),

将上面的最后一个 url 标识符更改为“video_player”以外的内容。

于 2012-10-11T15:03:24.007 回答
0

问题是您的标题匹配是贪婪的并且匹配的比您想要的更多,并且分隔您的部分的 / 包含在标题中,而 desc 是最后一个 / 之后的所有内容(在 url 中)

将其更改为非贪婪(?P<title>.+?)

url(r'^partner/(?P<author>[-\w]+)/(?P<video>[-\w]+)/(?P<title>.+?)/(?P<desc>.+)/$', 'video_player'),
于 2012-10-11T14:42:19.243 回答
0

给它s选择。默认情况下,.匹配换行符以外的任何字符。此外,您需要使您的标题部分不贪婪,否则它将与您的整个描述相匹配。使用.+?而不是.+这样做。

于 2012-10-11T14:43:17.770 回答