当我在我的视图.py它把我逼疯了。我不知道怎么解决这个问题。在
完全回溯
> Unhandled exception in thread started by <function check_errors.<locals>.wrapper at 0x000001E23A239400>
Traceback (most recent call last):
File "C:\Users\kr85m\AppData\Local\Programs\Python\Python36\lib\site-packages\django\utils\autoreload.py", line 225, in wrapper
fn(*args, **kwargs)
File "C:\Users\kr85m\AppData\Local\Programs\Python\Python36\lib\site-packages\django\core\management\commands\runserver.py", line 117, in inner_run
self.check(display_num_errors=True)
File "C:\Users\kr85m\AppData\Local\Programs\Python\Python36\lib\site-packages\django\core\management\base.py", line 379, in check
include_deployment_checks=include_deployment_checks,
File "C:\Users\kr85m\AppData\Local\Programs\Python\Python36\lib\site-packages\django\core\management\base.py", line 366, in _run_checks
return checks.run_checks(**kwargs)
File "C:\Users\kr85m\AppData\Local\Programs\Python\Python36\lib\site-packages\django\core\checks\registry.py", line 71, in run_checks
new_errors = check(app_configs=app_configs)
File "C:\Users\kr85m\AppData\Local\Programs\Python\Python36\lib\site-packages\django\core\checks\urls.py", line 13, in check_url_config
return check_resolver(resolver)
File "C:\Users\kr85m\AppData\Local\Programs\Python\Python36\lib\site-packages\django\core\checks\urls.py", line 23, in check_resolver
return check_method()
File "C:\Users\kr85m\AppData\Local\Programs\Python\Python36\lib\site-packages\django\urls\resolvers.py", line 396, in check
for pattern in self.url_patterns:
File "C:\Users\kr85m\AppData\Local\Programs\Python\Python36\lib\site-packages\django\utils\functional.py", line 37, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "C:\Users\kr85m\AppData\Local\Programs\Python\Python36\lib\site-packages\django\urls\resolvers.py", line 533, in url_patterns
patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
File "C:\Users\kr85m\AppData\Local\Programs\Python\Python36\lib\site-packages\django\utils\functional.py", line 37, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "C:\Users\kr85m\AppData\Local\Programs\Python\Python36\lib\site-packages\django\urls\resolvers.py", line 526, in urlconf_module
return import_module(self.urlconf_name)
File "C:\Users\kr85m\AppData\Local\Programs\Python\Python36\lib\importlib\__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 994, in _gcd_import
File "<frozen importlib._bootstrap>", line 971, in _find_and_load
File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 678, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "C:\Users\kr85m\Google Drive\gitlab\DeathToPlexus\DeathToPlexus\DeathToPlexus\urls.py", line 25, in <module>
path('management/new/customer', include('createCustomer.urls')),
File "C:\Users\kr85m\AppData\Local\Programs\Python\Python36\lib\site-packages\django\urls\conf.py", line 34, in include
urlconf_module = import_module(urlconf_module)
File "C:\Users\kr85m\AppData\Local\Programs\Python\Python36\lib\importlib\__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 994, in _gcd_import
File "<frozen importlib._bootstrap>", line 971, in _find_and_load
File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 678, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "C:\Users\kr85m\Google Drive\gitlab\DeathToPlexus\DeathToPlexus\createCustomer\urls.py", line 3, in <module>
from . import views
File "C:\Users\kr85m\Google Drive\gitlab\DeathToPlexus\DeathToPlexus\createCustomer\views.py", line 2, in <module>
from .forms import Opret_kunde_form
File "C:\Users\kr85m\Google Drive\gitlab\DeathToPlexus\DeathToPlexus\createCustomer\forms.py", line 7, in <module>
class Opret_kunde_form(ModelForm):
File "C:\Users\kr85m\AppData\Local\Programs\Python\Python36\lib\site-packages\django\forms\models.py", line 256, in __new__
apply_limit_choices_to=False,
File "C:\Users\kr85m\AppData\Local\Programs\Python\Python36\lib\site-packages\django\forms\models.py", line 139, in fields_for_model
opts = model._meta
AttributeError: 'function' object has no attribute '_meta'
在模型.py在
^{pr2}$在表单.py在
from django import forms
from .models import Opretkunde
from django.forms import ModelForm
class Opret_kunde_form(ModelForm):
class Meta:
model = Opretkunde
fields = ['Fornavn', 'Efternavn', 'Telefon', 'Adresse']
在视图.py在
from django.shortcuts import render
from .forms import Opret_kunde_form
# Create your views here.
def index(request):
if request.method == 'POST': #Påbegynder starten af scriptet hvis der observeres en POST request
form = Opret_kunde_form(request.POST, request.FILES) #initialiserer formen
if form.is_valid():
return render(request, 'createUser.html',)
Django模型子类
models.Model
,并且需要是一个类本身,因为这个类的实例将是一个模型实例。在这就是为什么会出现这个错误,函数没有属性
_meta
,因为函数不能有元类,只能有类。在相关问题 更多 >
编程相关推荐