[Answer]-Django urls regular expressions

1👍

The named group (?P<username>.*) will match any characters, zero or more times. in your username, including forward slashes.

In url patterns, it would be more common to use (?P<username>[-\w]+). This would match at least one character from the set of lowercase a-z, uppercase A-Z, digits 0-9 hyphens and underscores.

I also recommend that you add a trailing slash to your pattern for your profile view.

Putting it all together, I suggest you use the following as a starting point for your urls.py:

urlpatterns = patterns('',
   url(r'^users/(?P<username>[-\w]+)/$',direct_to_template, {'template':'accounts/profile.html'}, name='profile'), 
   (r'^users/(?P<username>[-\w]+)/', include('app.urls')), 
)

Leave a comment