简体   繁体   中英

Django form not submitting

Recently, I've been working on a project to make certain tasks that are crucial to a project I am a part of become a lot easier.

The form was working the last time I checked it (a month ago). Since then, I moved it off of my computer and on to a server. The form is no longer submitting.

#forms.py

from django import forms
from .models import OnlineEssay, HardCopy, FaceToFaceConference

class OnlineEssayClientForm(forms.ModelForm):
    class Meta:
        model = OnlineEssay
        fields = [
            "client_first_name",
            "client_last_name",
            "client_grade",
            "client_teacher",
            "client_email",
            "feedback_primary",
            "feedback_secondary",
            "essay_file",
        ]
        labels = {
            'client_first_name': ('First Name'),
            'client_last_name': ('Last Name'),
            'client_grade': ('Grade Level (As Number)'),
            'client_teacher': ('Teacher'),
            'client_email': ('Email Address'),
            'feedback_primary': ('I need/would like feedback on:'),
            'feedback_secondary': ('And,'),
        }


class OnlineEssayTutorForm(forms.ModelForm):
    class Meta:
        model = OnlineEssay
        fields = [
            "essay_type",
            "client_first_name",
            "client_last_name",
            "client_grade",
            "client_teacher",
            "client_email",
            "feedback_primary",
            "feedback_secondary",
            "essay_file",
            "essay_tutor",
            "essay_feedback",
        ]

class HardCopyTutorForm(forms.ModelForm):
    class Meta:
        model = HardCopy
        fields = [
            "essay_type",
            "client_first_name",
            "client_last_name",
            "client_grade",
            "client_teacher",
            "feedback_primary",
            "feedback_secondary",
            "essay_tutor",
            "essay_feedback",
        ]

class FaceToFaceConferenceTutorForm(forms.ModelForm):
    class Meta:
        model = FaceToFaceConference
        fields = [
            "essay_type",
            "client_first_name",
            "client_last_name",
            "client_grade",
            "client_teacher",
            "feedback_primary",
            "feedback_secondary",
            "essay_tutor",
            "essay_feedback_notes",
        ]

    <!-- templates/submit.html -->
    {% extends 'base.html' %}
    {% load crispy_forms_tags %}
    <!DOCTYPE html>
    <html lang="en">
    <head>
      <meta charset="UTF-8">
      {% block head_title %}Welcome{% endblock %}
    </head>
    <body>
      {% block content %}
      <h1>Submit Your Essay</h1>
      <div class="bs-callout bs-callout-default">
        <p>Fill Out The Form Below, then press Submit</p>
      </div
     <form method="post" enctype="multipart/form-data">{%csrf_token%}
        {{form|crispy}}
        <input class="btn btn-primary" type="submit" value="Submit" />
      </form>
      {% endblock %}
    </body>
    </html>


    #views.py
    from django.shortcuts import render
    from django import http

    # Create your views here.
    from .forms import OnlineEssayClientForm
    def submit(request):
    form = OnlineEssayClientForm(request.POST or None, request.FILES or None)
    context = {
        "form": form,
        "page_title" : "Submit Your Essay",
    }

    if form.is_valid():
       form.save()
       return http.HttpResponseRedirect('/success/')
    return render(request, "submit.html", context)

It was actually a pretty simple issue. I had forgot to close the </div> tag at the end of the callout. The form submits fine now.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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