首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Django提交表单工作开发而不是部署

Django提交表单工作开发而不是部署
EN

Stack Overflow用户
提问于 2016-11-26 18:06:37
回答 1查看 449关注 0票数 2

我有一个表单,它创建一个新的博客文章,并将我重定向到那个博客文章。表单在开发过程中正常工作,但是当我将应用程序部署到Heroku并单击submit按钮时,什么都不会发生。数据库、我的表单或管理功能(访问表单所需的)有什么问题吗?在数据库方面(如果与此有任何关系),我在上放置了一个.dump,并将其推送到我的数据库。任何帮助都会很好!

来自views.py的相关章节:

代码语言:javascript
复制
@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})  

表格:

代码语言:javascript
复制
{% 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 %}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-01-28 06:47:59

实际问题是迁移,如果您查看heroku日志中的内容,您将看到模型的relation错误。

为解决这一问题:

  1. 首先,确保已将所有迁移添加到git中: git add <myapp>/migrations/* git commit -m "Fix Heroku deployment" git push heroku
  2. 然后,通过运行以下命令,您需要在Heroku上再次迁移:

heroku run

代码语言:javascript
复制
~$  ./manage.py makemigrations
~$  ./manage.py migrate
~$  exit
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/40821438

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档