< 部署到Heroku后尝试打开博客页面时出现以下错误。它在cloud9中工作正常,但是一旦我部署它就会抛出错误。该网站的所有其他页面都可以正常工作。有人可以帮我吗?
[
Blog models.py file
from django.db import models
from django.utils import timezone
from django.urls import reverse
from django.conf import settings
from django.contrib.auth.models import User
from django.db.models.signals import pre_save
from django.utils.text import slugify
import datetime
class Post(models.Model):
author = models.ForeignKey('auth.User', on_delete=models.CASCADE, related_name='user')
title = models.CharField(max_length=200)
text = models.TextField()
created_date = models.DateTimeField(default=timezone.now)
published_date = models.DateTimeField(blank=True, null=True)
image = models.ImageField(upload_to='images', default='Upload Picture')
category = models.CharField(max_length=200)
description = models.CharField(max_length=340)
views = models.IntegerField(default=0)
likes = models.ManyToManyField(settings.AUTH_USER_MODEL, related_name='post_likes', blank=True)
def publish(self):
self.published_date = timezone.now()
self.save()
def approve_comments(self):
return self.comments.filter(approved_comment=True)
def get_absolute_url(self):
return reverse('post_detail', kwargs={"slug": self.slug})
def get_like_url(self):
return reverse('like', kwargs={"slug": self.slug})
def __str__(self):
return self.title
class Comment(models.Model):
post = models.ForeignKey('blog.Post', on_delete=models.CASCADE, related_name='comments')
author = models.CharField(max_length=200)
text = models.TextField()
created_date = models.DateTimeField(default=timezone.now)
approved_comment = models.BooleanField(default=False)
def approve(self):
self.approved_comment = True
self.save()
def get_absolute_url(self):
return reverse("post_list")
def __str__(self):
return self.text
settings.py文件中的数据库
!-开始代码段:js隐藏:虚假控制台:真babel:假->
# Database
# https://docs.djangoproject.com/en/1.11/ref/settings/#databases
if 'DATABASE_URL' in os.environ:
DATABASES = {
'default': dj_database_url.parse(os.environ.get('DATABASE_URL'))
}
else:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
}
}
答案 0 :(得分:0)
我解决了这个问题。 heroku中的postgres密钥与我在本地输入的密钥不同。我在本地更新,现在可以使用了。谢谢大家的时间,帮助和耐心。