gpt4 book ai didi

django - 在创建模型时获取 _wrapped_view() 至少需要 1 个参数(给定 0 个参数)

转载 作者:行者123 更新时间:2023-12-03 02:44:33 25 4
gpt4 key购买 nike

我有一份注册表单,提交后出现以下错误。

_wrapped_view() 至少需要 1 个参数(给定 0 个参数)

当我在 view.py 中实例化一个新的 UserProfile 对象(即 AppUserRegistration 函数)时,就会发生这种情况。

我正在用头撞墙。错误消息根本没有多大帮助。

models.py

class UserProfile(models.Model):
user = models.OneToOneField(User)
birthday = models.DateField(null=True, blank=True)
profession = models.CharField(max_length=100, null=True, blank=True)
created = models.DateTimeField()
modified = models.DateTimeField()

views.py

from django.http import HttpResponseRedirect
from django.contrib.auth.models import User
from django.contrib.auth.decorators import login_required
from django.shortcuts import render_to_response
from django.template import RequestContext
from AutoDIY.forms import RegistrationForm, LoginForm, UserProfileAboutForm
from AutoDIY.models import UserProfile
from django.contrib.auth import authenticate, login, logout

def AppUserRegistration(request):
if request.user.is_authenticated():
return HttpResponseRedirect('/')
if request.method == 'POST':
form = RegistrationForm(request.POST)
if form.is_valid():
first_name = form.cleaned_data.get('first_name')
last_name = form.cleaned_data.get('last_name')
username = form.cleaned_data.get('username')
email = form.cleaned_data.get('email')
password = form.cleaned_data.get('password')
user = User.objects.create_user(username=username,
email=email,
password=password)
user.first_name = first_name
user.last_name = last_name
user.save()
user_profile = UserProfile(user=user) # fails right here
...

注册.html

<form class="form-login form-wrapper form-medium" method="POST">
{% csrf_token %}
<h3 class="title-divider"><span>Sign Up</span>
<small>Already signed up? <a href="{% url login %}">Login here</a>.</small>
</h3>

{% if form.errors %}

<div class="alert alert-error">
<button type="button" class="close" data-dismiss="alert">&times;</button>
<strong>Please correct the following fields:</strong>
<ul>
{% if form.first_name.errors %}<li>First name</li>{% endif %}
{% if form.last_name.errors %}<li>Last name</li>{% endif %}
{% if form.username.errors %}<li>Username</li>{% endif %}
{% if form.email.errors %}<li>Email address</li>{% endif %}
{% if form.password.errors %}<li>Password</li>{% endif %}
{% if form.password1.errors %}<li>Password Verification</li>{% endif %}
</ul>
</div>

{% endif %}

<h5>Account Information</h5>
{{ form.first_name }}
{{ form.last_name }}
{{ form.username }}
{{ form.email }}
{{ form.password }}
{{ form.password1 }}
<label class="checkbox">
<input type="checkbox" value="term">
I agree with the Terms and Conditions.
</label>
<button class="btn btn-primary" type="submit">Sign up</button>
</form>

最佳答案

从您发布的错误来看,实际上 UserProfile 并不是一个模型类,而是一些函数(可能经过修饰)。检查您的代码库并确保您没有定义名为 UserProfile 的函数。也许您在views.py下面的某处有名为UserProfile的 View 函数?

关于django - 在创建模型时获取 _wrapped_view() 至少需要 1 个参数(给定 0 个参数),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15149678/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com