O
O
ozzat2017-04-17 18:39:13
Django
ozzat, 2017-04-17 18:39:13

How to fix a bug in Django?

I am new to Django. After reading the documentation and a few tutorials, I tried to make a website. But something is not right. The models seem to be well understood (the easiest :)). And the rest is out of hand, as much as the desire to study disappears. I did not find literature with good examples. Maybe you can tell me how to do it right?
PS Complains about the template.
Sample:

<div class="leftBox">
        <div class="categoryList">
          {%for material in materials%}				
          <div class="material">

            <div class="typedMaterialHeader">
              <div class="containImg"></div>
              <div class="matHeaderText">
                <span class="matName">{{material.material_title}}</span>
                <span class="matDate">17 июля 2016</span>
              </div>

            <div class="matText foldingText">{{material.material_text}}</div>

            <div class="matFooter">
              <span>Мне нравится</span></button>
              <span>Мне не нравится</span></button>
            </div>
          </div>
          {%endfor%}
</div>

Performance:
def materials (request):
  material = Material.objects.all()
  template = loader.get_template('templates/materials.html')
  context = Context({
    'material': material,
  })
  return HttpResponse(template.render(context))

Urls:
urlpatterns = [
    url(r'^admin/', admin.site.urls),
    url(r'^materials/', views.materials),
]

Models:
class Materials_Category (models.Model):
    name = models.CharField(max_length = 255, verbose_name = 'Название категории')
    class Meta:
        verbose_name = 'Материал'
        verbose_name_plural = 'Материалы'

class Material (models.Model):
    material_title = models.CharField(max_length=200)
    material_text = models.TextField()
    material_likes = models.IntegerField()
    category = models.ForeignKey(Materials_Category, null=True, blank=True)
    class Meta:
        verbose_name = 'Категория материалов'
        verbose_name_plural = 'Категории материалов'

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Dimonchik, 2017-04-17
@dimonchik2013

https://tutorial.djangogirls.org/en/

O
ozzat, 2017-04-18
@ozzat

It's decided. The problem was misrepresentation. Thanks to all.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question