Tuesday, January 31, 2017

RE: Link to urls containing slug

Hi David,

Please make sure you have a get_absolute_url method on your JobApplication model in order for that to work and that you passing job_application in through the context in the template.

If you don't have that method, you could use the {% url %} tag, but you would have to provide the pk and slug as arguments.

<a href="{% url  'job_application' pk=job_application.job_id slug=job_application.slug %}">{{ job_application }}</a>

 

Good luck!

 

From: 'David Turner' via Django users [mailto:django-users@googlegroups.com]
Sent: Tuesday, January 31, 2017 9:09 AM
To: django-users@googlegroups.com
Subject: Re: Link to urls containing slug

 

I had tried that but unfortunately it doesn't work but thanks anyway.

 

On 31/01/2017 14:57, Matthew Pava wrote:

Assuming I'm understanding your question correctly, all you need to do is reference get_absolute_url in your template.

Something like so:

 

<a href="{{ job_application.get_absolute_url }}">{{ job_application }}</a>

 

From: 'dtdave' via Django users [mailto:django-users@googlegroups.com]
Sent: Tuesday, January 31, 2017 8:46 AM
To: Django users
Subject: 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.

--
You received this message because you are subscribed to a topic in the Google Groups "Django users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/django-users/hlWrp8tzpXQ/unsubscribe.
To unsubscribe from this group and all its topics, 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/5e1e214b640c4d4f8c7c5e1d5cf0850b%40ISS1.ISS.LOCAL.
For more options, visit https://groups.google.com/d/optout.

 

--
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/5412da70-2ee1-9259-1f28-71e85e6e4ab9%40gmail.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment