On Thu, Sep 17, 2009 at 11:10 AM, Thomas <thomas.e.rectenw...@gmail.com>wrote:

>
> Hello,
>
> I'm learning Django and have some questions regarding passing data to
> urlpatterns.  Right now, I have something like this in my urls.py:
>
> urlpatterns = patterns('',
>    (r'^$', index),
>    (r'^list_jobs/', list_jobs),
> )
>
> This works fine.  I.e., any URL that matches ^list_jobs/ is handled by
> the list_jobs method in my views.py.  That calls a template which
> displays the list of jobs in an HTML table.
>
> So, now I have a list of jobs displayed in HTML, i.e. something like:
>
> Job | Severity | Message
>
> morning_job | INFO | Testing 123
> evening_job | ERROR | Testing 456
>
> My next step, I figured would be to have a user click on 'job1' or
> 'job2' in the table and call up information on that job in a new
> window.  So, I imagine that the correct way to do this within Django
> would be to have the HREF point to a the job in the URL.  I.e.:
>
> http://myserver:8000/morning_job
> http://myserver:8000/evening_job
>
> My next though was... grr, how do I do this?  So, I figured I can get
> the job names in the urls.py by first creating a method:
>
> from myapp.models import *
> def get_job_names():
>    job_names = []
>    for j in TransJob.objects.all():
>        job_names.append(j.job)
>    return job_names
> job_names = get_job_names()
>
> So, now I have a list (job_names) that would contain:
>
> ['morning_job', 'evening_job']
>
> I think I'm getting close.  Final step is to somehow take that list
> and put it within urlpatterns.  So, I tried something like:
>
> urlpatterns = patterns('',
>    (r'^$', index),
>    (r'^list_jobs/', list_jobs),
>    (job_names, list_job_details),
> )
>
> Here is where I get lost.  I think I'm going down the wrong path
> here.  The above comes back with a TypeError saying "unhashable type:
> 'list'" ... I'm guessing that you can't put a list in place of the raw
> string that the patterns method expects.  So, my question is... how do
> I get patterns to match all results for the list.
>
>
You are going down the wrong path.  You do not want to enumerate all
existing job values that might appear in url path segment in your URLConf.
Rather you want to describe via a regular expression what a job value might
look like, and put that in the url pattern.  If you have not run through the
tutorial I would suggest you do so, as it covers this subject.  In
particular I'd suggest you carefully go through:

http://docs.djangoproject.com/en/dev/intro/tutorial03/#design-your-urls

Karen

--~--~---------~--~----~------------~-------~--~----~
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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to