On Oct 13, 1:53 pm, Tim Chase <[EMAIL PROTECTED]> wrote:
> > I tried these, but I am missing a piece:
> > urlpatterns = patterns('',
> >     (r'^timesheet/(?P<username>)/$',
> > 'intranet.timesheets.views.times'),
> >     (r'^timesheet/(?P<username>\d{20})/$',
> > 'intranet.timesheets.views.times'),
> >     (r'^timesheet/(?P<user>\d{20})/(?P<date>\d{10})/$',
> > 'intranet.timesheets.views.times'),
> >     (r'^timesheet/(?P<user>\d{20})/$',
> > 'intranet.timesheets.views.times'),
> >     (r'^(?P<poll_id>\d+)/$', 'intranet.timesheets.views.login'),
> > )
> > Is a understand it, P tells django that this is python code.
> > d is the number of chars, but how does it know what user or date mean?
>
> Sounds like you could use some time with a regular-expression
> ("re", "regex" or "regexp") tutorial :)  They come in a variety
> of "flavors", each just maddeningly different from the next as to
> drive a fellow bonkers.  There are "POSIX regexps", "Perl
> regexps" (much like Python's), there are Vim regexps, and Visual
> Studio has its own flavor of them.  In this case, the regexps are
> Python regexps, the nuances of which are documented at
>
>    http://docs.python.org/lib/re-syntax.html
>
> There are several good books and websites that will teach you the
> basics of regexps, and a quick search will bring back a number of
> results.
>
> The (?P<name>...) captures the "..." regular expression, and
> calls it "name".  Thus, you need to fill in the "..." with a
> regular expression you want.  "\d" is "a digit", and "\w" are
> "word chars" (letters, numbers, and underscores).  This syntax of
> "(?P<name>...)" is called a "named capturing expression" because
> you give it a name.  Python's regexps also support un-named
> (positional) capturing which would just be "(...)".  These are
> then just assigned numeric indicies in the order they're
> encountered.  Django can use either for arguments to a view.
>
> Thus, you likely want something like
>
>    uname = '(?P<username>\w+)'
>      # a username is a "word character" ("\w")
>      # one or more times "+"
>    year = '(?P<year>\d{4})'
>      # a year is a digit ("\d") repeated 4x ("{4}")
>    month = '(?P<month>\d\d)'
>    day = month
>      # a day and a month are two digits ("\d\d")
>
>    r'^timesheet/' + uname + '/$'
>    r'^timesheet/' + uname + '/' + year + '/$'
>    r'^timesheet/' + uname + '/' + year + '/' + month + '/$'
>    # or be a bit fancy, and join them all together
>    '/'.join([
>      '^timesheet',
>      uname,
>      year,
>      month,
>      day,
>      '$'
>      ])
>
> These could then be passed to a view function like
>
>    def my_view(request, user, year=None, month=None, day=None):
>      # do something important here...
>      return render_to_response(...)
>
> Regular expressions are a powerful (and oft-abused) tool.  Most
> folks progress through the stages of
>
>    1) regular expressions scare me ("Agh, line-noise!")
>
>    2) regular expressions are the hammer with which I pound every
> nail ("how do I write a regex to parse XML?")
>
>    3) regular expressions are an indispensable tool certain jobs,
> but not a panacea
>
> Hope this helps...
>
> -tim

Thank alot thats the best response I have had.
What is: one or more times "+" mean?
How would I pass the whole date like 12/25/2008, I is freaking out
about the '/'?

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to