Python Django不会在POST中接收TextArea内容,但所有其他字段都会正常发送

Python Django不会在POST中接收TextArea内容,但所有其他字段都会正常发送,python,html,django,forms,post,Python,Html,Django,Forms,Post,我有一个HTML表单,我使用Django作为后端。所有其他字段都可以正常发送和接收,但application不能 apply.html <form action="/submit/" method="post"> {% csrf_token %} <div class="row"> <div class="three columns">

我有一个HTML表单,我使用Django作为后端。所有其他字段都可以正常发送和接收,但
application
不能

apply.html

        <form action="/submit/" method="post">
            {% csrf_token %}

            <div class="row">
                <div class="three columns">
                    <label for="{{ form.username.id_for_label }}">Username</label>
                    <input name="{{ form.username.html_name }}" class="u-full-width" type="text"
                           placeholder="inventor02" id="{{ form.username.auto_id }}" maxlength="34" required>
                </div>
                <div class="three columns">
                    <label for="{{ form.discriminator.id_for_label }}">Discriminator</label>
                    <input name="{{ form.discriminator.html_name }}" class="u-full-width" type="number"
                           placeholder="4201" id="{{ form.discriminator.auto_id }}" maxlength="4" required>
                </div>
                <div class="six columns">
                    <label for="{{ form.current_rank.id_for_label }}">Current Rank</label>
                    <input name="{{ form.current_rank.html_name }}" class="u-full-width" type="text"
                           placeholder="Member" id="{{ form.current_rank.auto_id }}" maxlength="30" required>
                </div>
            </div>

            <label for="{{ form.application.id_for_label }}">Application</label>
            <textarea name="{{ form.application.html_name }}" class="u-full-width"
                      placeholder="I would like to be staff because..." id="{{ form.application.auto_id }}"
                      required></textarea>

            <input class="button button-primary" type="submit" value="Submit">
        </form>
型号.py

def submit(request):
    if request.method == "POST":
        form = ApplicationForm(request.POST)
        print(request.POST)

        if form.is_valid():
            print(form)
            application = Application(username=form.cleaned_data["username"],
                                      discriminator=form.cleaned_data["discriminator"],
                                      current_rank=form.cleaned_data["current_rank"],
                                      application=form.cleaned_data["application"])
            application.save()

            return HttpResponse("<h1>Success!</h1>")
        else:
            return HttpResponse("Invalid form request. Try again.")
    else:
        return HttpResponse("You're accessing this using the wrong method. Go to the <a href=\"/apply\">apply</a> page.")
class ApplicationForm(forms.Form):
    username = forms.CharField(max_length=34)
    discriminator = forms.IntegerField(max_value=9999)
    current_rank = forms.CharField(max_length=30)
    application = forms.TextInput()
class Application(models.Model):
    username = models.CharField(max_length=34)
    discriminator = models.PositiveIntegerField()
    current_rank = models.CharField(max_length=50, default="Member")
    application = models.TextField()
    status = models.NullBooleanField(default=None)
    status_reason = models.TextField(default="Not yet reviewed")

    def __str__(self):
        return self.username + "#" + str(self.discriminator)

您真的应该在这里使用
模型表单。但无论如何,我认为你的问题与糟糕的
表格
定义有关:

class ApplicationForm(forms.Form):
    username = forms.CharField(max_length=34)
    discriminator = forms.IntegerField(max_value=9999)
    current_rank = forms.CharField(max_length=30)
    # application = forms.TextInput()
    application = forms.CharField(widget=forms.Textarea)
这应该可以解决问题。您应该尝试使用
ModelForm
,因为这将使保存模型等操作变得更加容易