python - Reverse URL issue -
i have django model defined
from utils.utils import apimodel django.db import models django.core.urlresolvers import reverse class djangojobposting(apimodel): title = models.charfield(max_length=50) description = models.textfield() company = models.charfield(max_length=25) def get_absolute_url(self): return reverse('jobs.views.jobdetail', args=[self.pk])
with view
from restless.views import endpoint restless.models import serialize .models import * utils.utils import json404 import ujson json class joblist(endpoint): def get(self, request): fields = [ ('url', lambda job: job.get_absolute_url()), 'title', ('description',lambda job: job.description[:50]), 'id' ] jobs = djangojobposting.objects.all() return serialize(jobs, fields) class jobdetail(endpoint): def get(self, request, pk): try: job = djangojobposting.objects.get(pk=pk) print(job) fields = ["title","description","company","id"] return serialize(job,fields) except exception e: return json404(e)
what have seen in other posts talk reverse method define first reverse parameter in terms specified above, urls.py uses same kind of definition, while mine uses
from django.conf.urls import patterns, include, url .views import * urlpatterns = patterns('', url(r'^$',joblist.as_view()), url(r'^(?p<pk>\d+)/$', jobdetail.as_view()), )
what keep getting error states
"reverse 'jobs.views.jobdetail' arguments '(1,)' , keyword arguments '{}' not found."
give urls names:
urlpatterns = patterns('', url(r'^$',joblist.as_view(), name='joblist'), url(r'^(?p<pk>\d+)/$', jobdetail.as_view(), name='jobdetail'), )
use name when call reverse
:
return reverse('jobdetail', args=[self.pk])
or
return reverse('jobdetail', kwargs={'pk': self.pk})
Comments
Post a Comment