值错误-未返回HttpResponse对象。它返回None

时间:2019-06-21 07:02:41

标签: django-forms

我正在尝试基于主管和客户模块开发项目 我想在主管页面中添加代理注册表格... 我通过导入UserRegistrationForm创建了注册表格... 现在,当我提交显示的数据时 “视图supervisor.views.agentreg没有返回HttpResponse对象。而是返回了None。”

here is my html template
  <body>
  {% if messages %}
  {% for message in messages %}
  <div class="alert alert-{{ message.tags }}">
    {{ message }}
 </div>
 {% endfor %}
 {% endif %}
 {% block content %}
 <div class="container">
  <div class="form-control">
  <h2>Agent Registration</h2>
    <form method="POST">
      {% csrf_token %}
      {{form.as_p}}
      <button type="submit" class="btn btn-success">submit</button>
    </form>
  </div>
 </div>
 {% endblock content %}
 </body>
  </html>

这是我的应用views.py文件

     def agentreg(request):
     if request.method == 'POST':
    form = AgentRegistrationForm(request.POST)
    if form.is_valid():
        form.save()
        username = form.cleaned_data.get('username')
        messages.success(request,f'Account Created for {username}!')
        return redirect('pendingtaks')
    else:
        form = AgentRegistrationForm()
        return render(request,'supervisor/agentreg.html',{'form':form})

这是我的forms.py文件

from django import forms
from django.contrib.auth.models import User
from django.contrib.auth.forms import UserCreationForm

class AgentRegistrationForm(UserCreationForm):
userid = forms.CharField(max_length=100)
usertype = forms.IntegerField()

class Meta:
    model = User
    fields = ['userid','username','password1','password2','usertype']

0 个答案:

没有答案