You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Django展示注册表单时报错:__init__()需1个参数却传入2个

Fix: init() takes 1 positional argument but 2 were given in Django Signup View

Hey, I see exactly where the issue is here—let's get this sorted out quickly!

The Root Cause

In your URL configuration line:

path('signup/', views.StudentSignUpView, name='signup')

You're passing the class itself (StudentSignUpView) to the path, but Django class-based views require you to call the as_view() method to turn them into a callable view function that can handle requests. When you skip as_view(), Django tries to instantiate the class directly with request arguments, which triggers that "1 positional argument but 2 were given" error.

The Fix

Update your URL path to use as_view():

path('signup/', views.StudentSignUpView.as_view(), name='signup')

Quick Double-Check for Future Stability

While we're at it, let's make sure a couple other critical pieces are in place:

  • Ensure your Student model has a proper one-to-one relationship with your custom User model (since you're creating a Student linked to the new user):
    class Student(models.Model):
        user = models.OneToOneField(User, on_delete=models.CASCADE)
        attended_courses = models.ManyToManyField(Course)
    
  • Confirm you've registered your custom User model in settings.py:
    AUTH_USER_MODEL = 'your_app_name.User'
    

That should resolve the immediate error and get your student signup form with course selection up and running smoothly!

内容的提问来源于stack exchange,提问作者user9092892

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.15 03:57:04