【问题标题】:How to fix TypeError at /admin/pages/course/add/ in Django admin?如何在 Django admin 中修复 /admin/pages/course/add/ 的 TypeError?
【发布时间】:2020-06-21 13:55:38
【问题描述】:

我在models.py 中完成了我的模型,并在makemigrations 之后运行迁移。我还在admin.py 注册了我的模型,我可以看到它出现在管理面板中。但是当我点击add course 时,它给了我以下错误:


TypeError at /admin/pages/course/add/
function missing required argument 'year' (pos 1)
Request Method: GET
Request URL:    http://127.0.0.1:8000/admin/pages/course/add/
Django Version: 3.0.7
Exception Type: TypeError
Exception Value:    
function missing required argument 'year' (pos 1)
Exception Location: C:\Users\ahnaa\OneDrive\Documents\Web Developent\Django\school_app\venv\lib\site-packages\django\db\models\fields\__init__.py in get_default, line 829
Python Executable:  C:\Users\ahnaa\OneDrive\Documents\Web Developent\Django\school_app\venv\Scripts\python.exe
Python Version: 3.8.3
Python Path:    
['C:\\Users\\ahnaa\\OneDrive\\Documents\\Web Developent\\Django\\school_app',
 'C:\\Users\\ahnaa\\AppData\\Local\\Programs\\Python\\Python38-32\\python38.zip',
 'C:\\Users\\ahnaa\\AppData\\Local\\Programs\\Python\\Python38-32\\DLLs',
 'C:\\Users\\ahnaa\\AppData\\Local\\Programs\\Python\\Python38-32\\lib',
 'C:\\Users\\ahnaa\\AppData\\Local\\Programs\\Python\\Python38-32',
 'C:\\Users\\ahnaa\\OneDrive\\Documents\\Web '
 'Developent\\Django\\school_app\\venv',
 'C:\\Users\\ahnaa\\OneDrive\\Documents\\Web '
 'Developent\\Django\\school_app\\venv\\lib\\site-packages']
Server time:    Sun, 21 Jun 2020 19:50:52 +0600

【问题讨论】:

  • 你能把你的模型贴出来

标签: python django django-models django-admin


【解决方案1】:

在您的课程模型中,转到年份模型并设置 null=True,blank=True 年份 = models.IntegerField(null=True, blank=True) 确保那里没有你不认识的论点。

【讨论】:

    猜你喜欢
    • 2013-10-24
    • 2011-02-04
    • 2013-04-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-08-09
    • 2011-02-25
    • 2018-11-15
    相关资源
    最近更新 更多