当我执行python manage.py runserver或makegrations时,出现此回溯问题。我哪里出问题了?请帮忙。我也想将其添加到管理网站。谢谢
这实际上只工作过一次,所以我不确定我做错了什么或为使该错误出现而进行了哪些更改。
回溯错误

    Exception in thread django-main-thread:
Traceback (most recent call last):
  File "C:\Users\Charlie\AppData\Local\Programs\Python\Python38-32\lib\threading.py", line 932, in _bootstrap_inner
    self.run()
  File "C:\Users\Charlie\AppData\Local\Programs\Python\Python38-32\lib\threading.py", line 870, in run
    self._target(*self._args, **self._kwargs)
  File "C:\Users\Charlie\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\utils\autoreload.py", line 54, in wrapper
    fn(*args, **kwargs)
  File "C:\Users\Charlie\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\core\management\commands\runserver.py", line 117, in inner_run
    self.check(display_num_errors=True)
  File "C:\Users\Charlie\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\core\management\base.py", line 387, in check
    all_issues = self._run_checks(
  File "C:\Users\Charlie\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\core\management\base.py", line 377, in _run_checks
    return checks.run_checks(**kwargs)
  File "C:\Users\Charlie\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\core\checks\registry.py", line 72, in run_checks
    new_errors = check(app_configs=app_configs)
  File "C:\Users\Charlie\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\contrib\admin\checks.py", line 56, in check_admin_app
    errors.extend(site.check(app_configs))
  File "C:\Users\Charlie\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\contrib\admin\sites.py", line 81, in check
    if modeladmin.model._meta.app_config in app_configs:
AttributeError: 'SubscriptionForm' object has no attribute 'model'
models.py
class Subscription(models.Model):
    firstName = models.CharField(max_length=100)
    lastName = models.CharField(max_length=100)
    username = models.CharField(max_length=100)
    sub_type = models.BooleanField()
    email = models.EmailField(max_length=100)
    address = models.CharField(max_length=100)
    address2 = models.CharField(max_length=100)
    country = models.CharField(max_length=100)
    state = models.CharField(max_length=100)
    zip = models.CharField(max_length=10)
    same_address = models.BooleanField()
    save_info = models.BooleanField()
    credit = models.BooleanField()
    debit = models.BooleanField()
    paypal = models.BooleanField()
    cc_name = models.CharField(max_length=100)
    cc_number = models.IntegerField()
    cc_expiration = models.CharField(max_length=10)
    cc_cvv = models.IntegerField()

    def __str__(self):
        return f'{self.firstName} {self.lastName}'
表格
class SubscriptionForm(forms.ModelForm):
    class Meta:
        model = Subscription
        fields = [
            'firstName',
            'lastName',
            'username',
            'sub_type',
            'email',
            'address',
            'address2',
            'country',
            'state',
            'zip',
            'same_address',
            'save_info',
            'credit',
            'debit',
            'paypal',
            'cc_name',
            'cc_number',
            'cc_expiration',
            'cc_cvv'

        ]
我已经追溯了自己的步骤,可以说当我尝试将订阅模型注册到管理页面时会发生这种情况。我应该从中导入
.models导入订阅或
.forms导入SubscriptionForm?
管理员
from django.contrib import admin

from .models import Profile, Subscription

admin.site.register(Profile, Subscription)
导入Subscription和SubscriptionForm时仍然出现相同的属性错误

最佳答案

您应该从模型导入并分别传递模型:

admin.site.register(Profile)
admin.site.register(Colaborador)
register()的第二个参数是ModelAdmin。
我不确定是否足够。将导入和文件路径添加到问题。

10-08 11:50