我有一个表单可以创建一个新的博客文章并将我重定向到该博客文章。该表单在开发中正常工作,但当我将应用程序部署到Heroku并单击提交按钮时没有任何反应。数据库,表单或管理功能(访问表单所需)有问题吗?就数据库而言(如果它与此有关)我在.Andode S3上放了一个.dump并将其推送到我的Heroku Postgres数据库。任何帮助都会很棒!
@login_required
def post_new(request):
if request.method == "POST":
form = PostForm(request.POST)
if form.is_valid():
post = form.save(commit=False)
post.author = request.user
post.save()
if post.category == 'progresstracker':
return redirect('books.views.pt_detail', slug=post.slug, category=post.category)
elif post.category == 'resources':
return redirect('books.views.resources')
else:
return redirect('books.views.bt_detail', slug=post.slug, category=post.category)
else:
form = PostForm()
return render(request, 'blog/post_edit.html', {'form': form})
def pt_detail(request, slug, category):
post = get_object_or_404(Post, slug=slug, category__slug=category)
template = CATEGORY_TEMPLATES.get(post.category.slug)
return render(request, template, {'post': post})
{% extends 'blog/base.html' %}
{% block nav %}
<li><a href="/home">Home</a></li>
<li><a href="/progresstracker">Progress Tracker</a></li>
<li class="dropdown">
<a href="/blogtopics" class="dropbtn">Blog Topics</a>
<div class="dropdown-content">
<a href="/blogtopics/computer-science">Computer Science</a>
<a href="/blogtopics/data-science">Data Science</a>
<a href="/blogtopics/other">Other</a>
</div>
</li>
<li><a href="/resources">Resources</a></li>
{% endblock %}
{% block content %}
<div id="content">
<div class="padding">
<h1>New post</h1>
<form method="POST" class="progresstracker-form">{% csrf_token %}
{{ form.as_p }}
<button type="submit" class="save btn btn-default">Save</button>
</form>
</div>
</div>
{% endblock %}
答案 0 :(得分:0)
真正的问题是迁移,如果您查看一下heroku日志,则会发现模型出现relation
错误。
要解决此问题:
首先请确保已将所有迁移都添加到git中 回购:
git add <myapp>/migrations/*
git commit -m "Fix Heroku deployment"
git push heroku
然后,您需要通过运行这些再次在Heroku上进行迁移 命令:
heroku运行bash
~$ ./manage.py makemigrations
~$ ./manage.py migrate
~$ exit