Tuesday, January 31, 2017

Link to urls containing slug

Within my model I have the following that links through to a detail page.

def get_absolute_url(self):

        

        kwargs = {

                  'job_id': self.job_id,

                  'slug': self.slug,

                       }

        return reverse('job_detail', kwargs=kwargs)


Everything works fine with this.


Within my urls.py I have the following:

url(r'^$', views.JobListView.as_view(), name='job_list'),

url(r'^(?P<job_id>[-\w]*)/(?P<slug>[-\w]*)/$', views.JobDetail.as_view(), name='job_detail'),

url(r'^(?P<job_id>[-\w]*)/(?P<slug>[-\w]*)/job_application/$', views.job_application, name='job_application'),


Then within my views.py the following:

def job_application(request, job_id, slug):

    # Retrieve job by id

    job = get_object_or_404(Job, job_id=job_id)

    """Other code here""""


However, I am having problems linking to this from my template in my detail page.

What structure should I be using to link to the job application from the job detail page?


I can access the url by going to 

http://localhost:8000/jobs/1/name-of-job/job_application/


Any advice would be appreciated

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/0e6db077-52a8-4f23-862c-888ae0995e91%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment