E
E
er122013-12-15 17:20:25
Django
er12, 2013-12-15 17:20:25

What causes an error when passing data by reference?

There is index.html, which contains only the title of the work (title) (is a link). When you click on this link, the name of the work and the cost are displayed. The problem is that the transition does not display any information.
Here is model.py

from django.db import models

class Job(models.Model):
    #должность
    position= models.CharField(max_length=50)
    salary= models.IntegerField()
    def __unicode__(self):
     return self.position

Here is views.py:
def index(request):

    position = Job.objects.order_by('position')[:5]

    return render(request, 'job/index.html',
                    {

                    'position' : position,

                    }
                    )





def job(request, job_id):
    position = get_object_or_404(Job, pk=job_id)
    return render(request, 'job/job.html',
                    {
                      'position': position
                    }
                    )

Here is index.html
{% if position %}
    <ul>
    {% for job in position %}
        <li><a href="{% url 'job' job_id=job.id %}">{{ job.position }}</a></li>
    {% endfor %}
    </ul>
{% else %}
    <p>No job are available.</p>
{% endif %}

Here is job.html
<h1>{{ job.position }}</h1>
<ul>
    <li>{{ job.salary }}</li>

</ul>

Here is urls.py
from job import views

urlpatterns = patterns('',

    url(r'^$', 'job.views.index', name='index'),

    url(r'^(?P<job_id>\d+)/$', views.job, name='job'),

)

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
SilentSokolov, 2013-12-15
@er12

def job(request, job_id):
    position = get_object_or_404(Job, pk=job_id)
    return render(request, 'job/job.html',
                    { 'position': position} )

Passing the position to the template
<h1>{{ job.position }}</h1>
<ul>
    <li>{{ job.salary }}</li>

</ul>

In the template, you refer to job

E
er12, 2013-12-15
@er12

Thank you

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question