简体   繁体   English

Django提交表单工作开发未部署

[英]Django Submit Form Working Development Not Deployment

I have a form that creates a new blog post and redirects me to that blog post. 我有一个创建新博客文章并将我重定向到该博客文章的表格。 The form works properly in development but when I deployed the app to Heroku and click the submit button nothing happens. 该表单在开发中可以正常工作,但是当我将应用程序部署到Heroku并单击“提交”按钮时,没有任何反应。 Is something wrong with the database, my form, or the admin functionality (which is required to access the form)? 数据库,我的表单或管理功能(访问表单所需)是否有问题? In terms of the database (in case it has anything to do with that) I put a .dump on Amazon S3 and pushed it to my Heroku Postgres database. 在数据库方面(如果与它有任何关系),我在Amazon S3上放了一个.dump并将其推到我的Heroku Postgres数据库中。 Any help would be great! 任何帮助将是巨大的!

Relevant section from views.py: views.py中的相关部分:

@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})  

The form: 表格:

{% 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 %}

The actual issue is the migrations, If you will take a look inside the heroku logs you will see a relation error for your model. 实际的问题是迁移,如果您查看一下heroku日志,则会看到模型的relation错误。

To solve this issue: 要解决此问题:

  1. First make sure you have added all the migrations to the git repo: 首先确保您已将所有迁移添加到git repo中:

    git add <myapp>/migrations/* git commit -m "Fix Heroku deployment" git push heroku

  2. Then you need to migrate once again on Heroku by running these commands: 然后,您需要通过运行以下命令在Heroku上再次迁移:

heroku run bash heroku运行bash

~$  ./manage.py makemigrations
~$  ./manage.py migrate
~$  exit

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM