Django Wang novice's question! I can't print it out from the long-range db.

Asked 2 years ago, Updated 2 years ago, 101 views

# index.html
<tbody>
       {% {% for post in job_opening %}
        <tr>
             <td>{{ post.title }}</td>
             <td>{{ post.target }}</td>
             <td>{{ post.department }}</td>
             <td>{{ post.period }}</td>
             <td> Button</td>
         </tr>
        {% {% endfor %}
</tbody>
# view.py
def index(request):
    template = loader.get_template('mainapp/index.html')
    post = job_opening.objects.all()
    context = {'post' : post}
    return render(request, 'mainapp/index.html', context)

# models.py
class job_opening(models.Model):
    title = models.CharField(max_length=200,verbose_name='title')
    target = models.CharField(max_length=50)
    department = models.CharField(max_length=10)
    period = models.CharField(max_length=50)
    content = models.TextField()

    def __str__(self):
        return self.title

Add job_opening in admin

When I turn on the site, I can't print it out to the table...ㅜ<

djago-model django django-view

2022-09-21 16:21

1 Answers

I think it's confusing because similar names are repeated. If you change the sauce like this, it'll probably work.

# view.py
foo = job_opening.objects.all()
bar = {'dee' : foo}
return render(request, 'mainapp/index.html', bar)
<!-- index.html -->
{% {% for post in dee %}


2022-09-21 16:21

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.