from django.db import models
from django.utils import timezone
class Post(models.Model):
author = models.ForeignKey('auth.User')
title = models.CharField(max_length=200)
text = models.TextField()
image = models.ImageField(upload_to='images/', null=True, blank=True)
created_date = models.DateTimeField(
default=timezone.now)
published_date = models.DateTimeField(
blank=True, null=True)
def publish(self):
self.published_date = timezone.now()
self.save()
def __str__(self):
return self.title
<html>
<head>
<title>Django blog</title>
</head>
<body>
<p>Hello, world</p>
<hr/>
<p>second string</p>
<hr/>
{% for post in posts %}
<div>
<p>published: {{ post.published_date }}</p>
<h1><a href="">{{ post.title }}</a></h1>
<p>{{ post.text|linebreaksbr }}</p>
<p>{{post.image}}</p>
</div>
{% endfor %}
</body>
</html>
images/1._Черный_кот_с_рыбкой_aX8Xrxu.jpg
вот мой urls в приложении blog :