姜戈2.0
我创建了一个模型Blog app,
class Category(models.Model):
field1 = models....
field2 = models....
field3 = models....
Run Code Online (Sandbox Code Playgroud)
一段时间后,我想在该模型中添加一个新字段。
class Category(models.Model):
field1 = models....
cover_pic = .models....
field2 = models....
field3 = models....
Run Code Online (Sandbox Code Playgroud)
我遵循了这个答案。但它给了我以下错误。
django.db.utils.OperationalError: (1054, "Unknown column 'blog_category.cover_pic' in 'field list'")
我从我的Post模型中获取数据并简单地传递到模板中。但是输出显示在双引号中。我的 Post 模型中有 html 标签,它不是渲染而是显示为代码。
视图.py
# It display the single post
def single_post(request,cat,post_id,post_title):
single_post = Post.objects.get(pk = post_id)
return render(request, 'blog/single_post.html', {'single_post': single_post})
Run Code Online (Sandbox Code Playgroud)
single_post.html
<h1>I'm single post page</h1>
{{single_post.title}}
<br>
<br>
{{single_post.content}}
Run Code Online (Sandbox Code Playgroud)
浏览器输出