I tried to use this pattern to pass 2 parameters in an URL, where the second parameter is optional. This is my code:
urlpatterns = patterns('',
url(r'^topic/(?P<topic>.*)/(?P<page>.*)/$', activities_list,
url(r'^topic/(?P<topic>.*)/$', activities_list, name='activities'),name='activities_page'),
)
This works, except when the second parameter is 1
. In that case, topic is topic/1
and and page is None
. It works for any other number as a second parameter.
Who can put me in the right direction to solve this bug?
UPDATE, this is getting weird
After trying several things, I discovered that this template tag makes the problem:
<img src="{{recommendation.user_picture_url}}" />
When I delete this tag, or even remove it from the src attribute and place it outside the image tag, the URL works. The variable contains a URL to a LinkedIn avatar on Linkedin's servers.
This is my view
def activities_list(request, topic, page=1):
print topic
print page
...
return render_to_response(...
I don't understand why my view is getting the wrong parameters from the URL (as seen in the prints), while the hole response hasn't even been rendered yet.
Update: Solved! (see below)