Answer the question
In order to leave comments, you need to log in
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
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
}
)
{% 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 %}
<h1>{{ job.position }}</h1>
<ul>
<li>{{ job.salary }}</li>
</ul>
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
def job(request, job_id):
position = get_object_or_404(Job, pk=job_id)
return render(request, 'job/job.html',
{ 'position': position} )
<h1>{{ job.position }}</h1>
<ul>
<li>{{ job.salary }}</li>
</ul>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question