该应用程序是一个博客文章应用程序,在本地运行良好,但是在将其部署到Heroku之后,该应用程序无法运行。我花了一个多星期的时间试图通过视图和模型修复它,但没有成功。
This Is The Error When Trying To Open The App
views.py
from django.shortcuts import render,get_object_or_404, get_list_or_404
from posts.models import Post, Category
# Create your views here.
import datetime
def index(request):
now = datetime.datetime.now()
big_slider_list = Post.objects.filter(category__name='Big_Slider')
news_box_list = Post.objects.filter(category__name='People')
cote_divoire_list = Post.objects.filter(category__name="Côte d'Ivoire").exclude(position=1)
block1_big = Post.objects.filter(position=1)
culture_list = Post.objects.filter(category__name="Culture").exclude(position=2)
block2_big = Post.objects.filter(position=2)
sport_list = Post.objects.filter(category__name="Sports").exclude(position=3)
block3_big = Post.objects.filter(position=3)
infrast_et_devel_list = Post.objects.filter(category__name="Infrastructures Et Dévelopements")
context = {
'now': now,
'big_slider_list': big_slider_list[:10],
'news_box_list': news_box_list[:4],
'cote_divoire_list': cote_divoire_list[:4],
'block1_big': block1_big[0],
'culture_list': culture_list[:3],
'block2_big': block2_big[0],
'sport_list': sport_list[:3],
'block3_big': block3_big[0],
'infrast_et_devel_list': infrast_et_devel_list[:3],
}
return render(request, 'home/index.html', context)
models.py:
from django.db import models
from django.contrib.auth import get_user_model
from django.urls import reverse
# Create your models here.
User = get_user_model()
STATUS = (
(0, "Draft"),
(1, "Publish")
)
POSITIONS = [
(0, ' '),
(1, 'BIG_BLOCK_1'),
(2, 'BIG_BLOCK_2'),
(3, 'BIG_BLOCK_3'),
(4, 'BIG_BLOCK_4'),
]
class Author(models.Model):
name = models.CharField(max_length=50)
user = models.OneToOneField(User, on_delete=models.CASCADE)
profile_picture = models.ImageField(null=True, blank=True)
email = models.EmailField(unique=True)
active = models.BooleanField(default=False)
created_on = models.DateTimeField(auto_now_add=True)
last_logged_in = models.DateTimeField(auto_now=True)
def __str__(self):
return self.user.username
class Category(models.Model):
country = models.CharField(max_length=200, blank=True)
name = models.CharField(max_length=100, unique=True)
slug = models.SlugField(max_length=100, unique=True)
author = models.ForeignKey(Author, on_delete=models.CASCADE,)
def __str__(self):
return self.name
def get_absolute_url(self):
return reverse('posts:post_by_category', args=[self.slug])
class Tag(models.Model):
name = models.CharField(max_length=100, unique=True)
slug = models.SlugField(max_length=100, unique=True)
author = models.ForeignKey(Author, on_delete=models.CASCADE,)
def __str__(self):
return self.name
def get_absolute_url(self):
return reverse('posts:post_by_tag', args=[self.slug])
class Post(models.Model):
status = models.IntegerField(choices=STATUS, default=0)
position = models.IntegerField(choices=POSITIONS, default=0)
title = models.CharField(max_length=300)
short_title = models.CharField(max_length=200)
display_image = models.ImageField(null=True, blank=True)
post_image = models.ImageField(null=True, blank=True)
content = models.TextField(max_length=8000)
slug = models.SlugField(max_length=300, unique=True)
updated_on = models.DateTimeField(auto_now=True, auto_now_add=False)
created_on = models.DateTimeField(auto_now=False, auto_now_add=True)
author = models.ForeignKey(Author, on_delete=models.CASCADE,)
category = models.ForeignKey(Category, on_delete=models.CASCADE,)
tags = models.ManyToManyField(Tag,)
comment_count = models.IntegerField(default=0)
class Meta:
ordering = ['-created_on']
verbose_name = "All Post"
def __str__(self):
return self.title
def get_absolute_url(self):
return reverse('posts:post_detail', kwargs={'slug': self.slug})
class Comment(models.Model):
post = models.ForeignKey(Post, on_delete=models.CASCADE, related_name='comments')
name = models.CharField(max_length=80)
email = models.EmailField()
body = models.TextField()
created_on = models.DateTimeField(auto_now_add=True)
active = models.BooleanField(default=False)
class Meta:
ordering = ['created_on']
def __str__(self):
return 'Comment {} by {}'.format(self.body, self.name)
答案 0 :(得分:0)
这与迁移有关。您的本地数据库已应用了所有迁移,而Heroku上的数据库没有post
字段。也许您稍后添加/编辑了该字段,因此您的两个数据库不同步。由于这似乎是一个没有数据的新项目,因此您可以更轻松地heroku reset
将heroku数据库和push
本地数据库连接到heroku。以下是说明:https://devcenter.heroku.com/articles/heroku-postgres-import-export