Using Django url regex for nested routes -


hi excited move rails django having trouble.

the following has urls , corresponding view's action. when both urls enabled, publisherdomain breaks publisherssingle(page visitable not rendering content. when publisherdomain code commented out, publisherssingle works , renders right content. question is: whats wrong causing on ride , break? pasted elements believe theres wrong.

urls.py

url(r'^publishers/(?p<domain>.*)/$', 'firm.views.publisherdomain'), url(r'^publishers/(?p<domain>.*)/(?p<period>.*)/$', 'firm.views.publisherssingle'), 

views.py

def publisherdomain(request, domain):    return render_to_response()  def publishersingle(request, domain, period):    return render_to_response. 

the problem regex. in matching group (?p<domain>.*), .* matches 0 or more of any character, including forward slashes. means first url pattern matches /publishers/domain/period/, request handled publisherdomain view instead of publishersingle.

a more common regex (?p<domain>[\w-]+), match 1 or more uppercase letters a-z, lowercase a-z, digits 0-9, hyphen or underscore.

as aside, please consider following python convention , naming view functions publisher_domain , publisher_single. python programmer, name publisherdomain looks class, not function.


Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -