Answer the question
In order to leave comments, you need to log in
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>
def materials (request):
material = Material.objects.all()
template = loader.get_template('templates/materials.html')
context = Context({
'material': material,
})
return HttpResponse(template.render(context))
urlpatterns = [
url(r'^admin/', admin.site.urls),
url(r'^materials/', views.materials),
]
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
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question