Hi Serge,
The following works and is almost the same as your code:
url_list = []
for i in range(0, 4):
url_list.append(url(r'^%d$' % i, 'view%d' % i))
urlpatterns = patterns('', *url_list)
As patterns is a function that expects multiple arguments each of which
(other than the first) is a url pattern, you need to pass *url_list to it
and not url_list.
As for your error on the url(), the error indicates that though the
function has received 2 arguments it hasn't received the two *required*
arguments it needs, this could be if in the actual code you are passing one
optional keyword argument. Could you paste the exact url call from your
code?
Regards,
Atul
On Saturday, 9 March 2013 06:03:05 UTC+11, Serge G. Spaolonzi wrote:
>
> I am looking the way to create urls on the fly.
> This is a simplified version of the code I am using:
>
> def get_urls():
> url_list = []
> for code in external_code_list:
> url_list.append(
> url(r'^%s/$' % code,
> view
> )
> )
> urlpatterns = patterns('', url_list)
> return urlpatterns
>
>
> urlpatterns = get_urls()
>
> It throws "url() takes at least 2 arguments (2 given)"
>
> Any idea?
>
> Thanks
>
> --
> Serge G. Spaolonzi
> Cobalys Systems
> http://www.cobalys.com
>
--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.