Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Django表单错误(\uuuu init\uuuu()接受1个位置参数,但给出了2个)_Python_Django_Django Class Based Views - Fatal编程技术网

Python Django表单错误(\uuuu init\uuuu()接受1个位置参数,但给出了2个)

Python Django表单错误(\uuuu init\uuuu()接受1个位置参数,但给出了2个),python,django,django-class-based-views,Python,Django,Django Class Based Views,我使用Django 1.11和python 3.6.5。我制作了一个模型和一个用户注册表格。一切似乎都很好,只是我有一个我无法解决的错误 __init__() takes 1 positional argument but 2 were given 模型如下: from django.db import models class User_account(models.Model): first_name = models.CharField(max_length=64) last_nam

我使用Django 1.11和python 3.6.5。我制作了一个模型和一个用户注册表格。一切似乎都很好,只是我有一个我无法解决的错误

__init__() takes 1 positional argument but 2 were given
模型如下:

from django.db import models

class User_account(models.Model):

first_name = models.CharField(max_length=64)
last_name = models.CharField(max_length=64)
user_name = models.CharField(max_length=128)
email = models.EmailField(max_length=254, blank=False, unique=True)
password = models.CharField(max_length=64) 
address = models.ForeignKey(Address, on_delete=models.CASCADE)
表格如下:

from django import forms
from .models import User_account

class User_accountForm(forms.ModelForm):

    class Meta:
        model = User_account
        fields = ['first_name', 'last_name', 'user_name', 'email', 'password', 'address']
以下是视图的一部分:

from django.shortcuts import render, redirect
from .models import *
from django.views import View
from .forms import *
from django.contrib.auth import authenticate, login


class User_accountFormView(View):
    form_class = User_accountForm
    template_name = 'towns/salehslist/registeration_form.html'

    # display a blank form
    def get(self, request, *args, **kwargs):
        form = self.form_class(None)

        return render(request, self.template_name, {'form':form})
网址:

from django.conf.urls import url

from . import views

urlpatterns = [

    url(r'^$', views.index, name='index'),
    url(r'^register/$', views.User_accountFormView, name='register'),

在url模式中包含基于类的视图时,需要调用
作为\u view()

url(r'^register/$', views.User_accountFormView.as_view(), name='register'),