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.
I hope this makes some sense. I tried to be verbose as I'm new to the
framework. Thanks for any assistance.
Regards,
Thomas
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to [email protected]
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
-~----------~----~----~----~------~----~------~--~---