【发布时间】:2020-09-11 14:34:34
【问题描述】:
我正在制作一个简单的个人网站。我制作了一个框来输入用户数据(姓名、电子邮件和消息)。我希望将此数据发送给我的 django 管理员。我已经对其进行了测试,并且可以在本地使用。但是当我部署它时,每当我从盒子里提交时,我都没有得到任何数据。注意:出于某种原因,我不使用 django 形式。我想使用自己的自定义表单。
这是我的 views.py
from django.shortcuts import render
from django.http import HttpResponse
from .models import Feedback
from .forms import FeedbackForm
def index(request):
if (request.method == "POST"):
name = request.POST.get("Name")
email = request.POST.get("Email")
message = request.POST.get("Message")
record = Feedback(name=name, email=email, message=message)
record.save()
return render(request, 'main.html')
这是我的 models.py
from django.db import models
class Feedback(models.Model) :
name = models.CharField(max_length=50)
email = models.EmailField()
message = models.CharField(max_length=200)
def __str__(self):
return self.name
这是我的 html 表单
<form action="{% url 'index' %}" method="POST" target="_self">
{% csrf_token %}
<div class="w3-row-padding" style="margin:0 -16px 8px -16px">
<div class="w3-half">
<input class="w3-input w3-border" type="text" placeholder="Name" required name="Name" >
</div>
<div class="w3-half">
<input class="w3-input w3-border" type="email" placeholder="Email" required name="Email">
</div>
</div>
<input class="w3-input w3-border" type="text" placeholder="Message" required name="Message" >
<button class="w3-button w3-black w3-right w3-section" type="submit">
<i class="fa fa-paper-plane"></i> SEND MESSAGE
</button>
</form>
【问题讨论】:
-
需要更多细节。请输入表格和阿明。没有错误吗?
-
如果设置 DEBUG = True,它会抛出任何错误吗?项目部署在什么平台上?
-
因为我没有使用 django 表单所以我不使用 forms.py。我只是在使用我的 html 表单@babakgholamirad
-
没有发生错误。该应用程序适用于本地和部署@nightwolfgroup